fix crash when switching maps in global map

This commit is contained in:
Ondřej Novák 2025-03-01 20:19:53 +01:00
parent 1e7bbcb245
commit 9b199b13a7
4 changed files with 61 additions and 51 deletions

View file

@ -61,7 +61,7 @@ char enable_glmap=0;
static int map_xr,map_yr;
static int cur_depth;
TSTR_LIST texty_v_mape=NULL;
static TSTR_LIST texty_v_mape=NULL;
#define BOTT 378
#define LEFT 520
@ -96,7 +96,6 @@ T_CLK_MAP clk_teleport_view[]=
{-1,0,0,639,479,empty_clk,0xff,-1},
};
char testclip(int x,int y)
{
return (y>=16 && y<360+16 && x>=8 && x<630);
@ -1054,3 +1053,54 @@ int select_teleport_target(char nolimit)
disable_all_map();
return last_selected;
}
void save_map_description(TMPFILE_WR *f)
{
int count,max;
int32_t i;
if (texty_v_mape==NULL) max=0;else max=str_count(texty_v_mape);
for(i=0,count=0;i<max;i++) if (texty_v_mape[i]!=NULL) count++;
temp_storage_write(&count,1*sizeof(count),f);
for(i=0;i<max;i++) if (texty_v_mape[i]!=NULL)
{
word len;
len=strlen(texty_v_mape[i]+12)+12+1;
temp_storage_write(&len,1*2,f);
temp_storage_write(texty_v_mape[i],1*len,f);
}
}
void load_map_description(TMPFILE_RD *f)
{
int32_t count;
int32_t i;
word len;
if (texty_v_mape!=NULL)release_list(texty_v_mape);
temp_storage_read(&count,1*sizeof(count),f);
if (!count)
{
texty_v_mape=NULL;
return;
}
texty_v_mape=create_list(count);
for(i=0;i<count;i++)
{
temp_storage_read(&len,1*2,f);
{
char *s;
s=(char *)alloca(len);
memset(s,1,len-1);
s[len-1]=0;
str_replace(&texty_v_mape,i,s);
}
temp_storage_read(texty_v_mape[i],1*len,f);
}
}
void free_map_description() {
if (texty_v_mape!=NULL)release_list(texty_v_mape);
texty_v_mape = NULL;
}

View file

@ -235,52 +235,7 @@ void restore_items(TMPFILE_RD *f)
}
extern TSTR_LIST texty_v_mape;
void save_map_description(TMPFILE_WR *f)
{
int count,max;
int32_t i;
if (texty_v_mape==NULL) max=0;else max=str_count(texty_v_mape);
for(i=0,count=0;i<max;i++) if (texty_v_mape[i]!=NULL) count++;
temp_storage_write(&count,1*sizeof(count),f);
for(i=0;i<max;i++) if (texty_v_mape[i]!=NULL)
{
word len;
len=strlen(texty_v_mape[i]+12)+12+1;
temp_storage_write(&len,1*2,f);
temp_storage_write(texty_v_mape[i],1*len,f);
}
}
void load_map_description(TMPFILE_RD *f)
{
int32_t count;
int32_t i;
word len;
if (texty_v_mape!=NULL)release_list(texty_v_mape);
temp_storage_read(&count,1*sizeof(count),f);
if (!count)
{
texty_v_mape=NULL;
return;
}
texty_v_mape=create_list(count);
for(i=0;i<count;i++)
{
temp_storage_read(&len,1*2,f);
{
char *s;
s=(char *)alloca(len);
memset(s,1,len-1);
s[len-1]=0;
str_replace(&texty_v_mape,i,s);
}
temp_storage_read(texty_v_mape[i],1*len,f);
}
}
void save_vyklenky(TMPFILE_WR *fsta)
{
@ -1802,7 +1757,10 @@ static int load_map_state_partial(char *level_fname,int mapsize) //obnovuje stav
bf=(char *)getmem(siz);
if (!temp_storage_read(bf,siz*1,fsta)) goto err;
for (i=0;i<mapsize;i++)
map_coord[i].flags|=(bf[i>>3]>>(i & 7)) & 1;
if ((bf[i>>3]>>(i & 7)) & 1) map_coord[i].flags|=MC_AUTOMAP;
if (!temp_storage_read(bf,siz*1,fsta)) goto err;
for (i=0;i<mapsize;i++)
if ((bf[i>>3]>>(i & 7)) & 1) map_coord[i].flags|=MC_DISCLOSED;
load_map_description(fsta);
while (temp_storage_read(&i,1*2,fsta) && i<=mapsize*4)
if (temp_storage_read(map_sides+i,1*sizeof(TSTENA),fsta)!=sizeof(TSTENA)) goto err;

View file

@ -1406,6 +1406,9 @@ int load_map_state(void); //obnovuje stav mapy; nutno volat po zavolani load_map
void restore_current_map(void); //pouze obnovuje ulozeny stav aktualni mapy
int load_game(const char *fname);
int save_game(long game_time,char *gamename, char is_autosave);
void save_map_description(TMPFILE_WR *f);
void load_map_description(TMPFILE_RD *f);
void free_map_description();
void wire_save_load(char save);
void do_save_dialog();
char ask_save_dialog(char *name_buffer, size_t name_size);

View file

@ -47,7 +47,7 @@
#define DIS (char *)0x1
#define START_HANDLE hl_ptr
extern TSTR_LIST texty_v_mape;
@ -457,14 +457,13 @@ void leave_current_map()
free(flag_map);
free(map_coord);
free(map_vyk);map_vyk=NULL;vyk_max=0;
if (texty_v_mape!=NULL)release_list(texty_v_mape);
free_map_description();
while (d_action!=NULL)
{
void *p=d_action;
d_action=d_action->next;
free(p);
}
texty_v_mape=NULL;
release_list(level_texts);
if (mob_map!=NULL) free(mob_map);
if (macro_block!=NULL)