fix crash entering sopka.map for second time

This commit is contained in:
Ondřej Novák 2025-02-05 10:41:40 +01:00
parent 93caf370e4
commit 0ae638276e
3 changed files with 10 additions and 9 deletions

View file

@ -455,7 +455,7 @@ static PARSED_COMMAND parse_command(const char *cmd) {
extern int ghost_walls; extern int ghost_walls;
extern int nofloors; extern int nofloors;
static int add_file_to_console(const char *name, LIST_FILE_TYPE , size_t, void *ctx) { static int add_file_to_console(const char *name, LIST_FILE_TYPE _, size_t __, void *ctx) {
int *cnt = (void *)ctx; int *cnt = (void *)ctx;
char buff[20] = ""; char buff[20] = "";
for (int i = 0; i < 19; ++i) buff[i] = ' '; for (int i = 0; i < 19; ++i) buff[i] = ' ';

View file

@ -218,14 +218,14 @@ extern TSTR_LIST texty_v_mape;
void save_map_description(TMPFILE_WR *f) void save_map_description(TMPFILE_WR *f)
{ {
int count,max; int count,max;
int i; int32_t i;
if (texty_v_mape==NULL) max=0;else max=str_count(texty_v_mape); 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++; for(i=0,count=0;i<max;i++) if (texty_v_mape[i]!=NULL) count++;
temp_storage_write(&count,1*sizeof(count),f); temp_storage_write(&count,1*sizeof(count),f);
for(i=0;i<max;i++) if (texty_v_mape[i]!=NULL) for(i=0;i<max;i++) if (texty_v_mape[i]!=NULL)
{ {
int len; word len;
len=strlen(texty_v_mape[i]+12)+12+1; len=strlen(texty_v_mape[i]+12)+12+1;
temp_storage_write(&len,1*2,f); temp_storage_write(&len,1*2,f);
temp_storage_write(texty_v_mape[i],1*len,f); temp_storage_write(texty_v_mape[i],1*len,f);
@ -234,8 +234,8 @@ void save_map_description(TMPFILE_WR *f)
void load_map_description(TMPFILE_RD *f) void load_map_description(TMPFILE_RD *f)
{ {
int count; int32_t count;
int i; int32_t i;
word len; word len;
if (texty_v_mape!=NULL)release_list(texty_v_mape); if (texty_v_mape!=NULL)release_list(texty_v_mape);
@ -328,8 +328,9 @@ int load_all_fly(TMPFILE_RD *fsta)
memcpy(n->items,items,(c-items)*sizeof(short)); memcpy(n->items,items,(c-items)*sizeof(short));
} }
add_fly(n); add_fly(n);
temp_storage_read(&sz,sizeof(sz),fsta);
} }
return 0; return sz != 0;
} }
@ -441,9 +442,9 @@ int load_map_state() //obnovuje stav mapy; nutno volat po zavolani load_map;
for (i=0;i<mapsize;i++) for (i=0;i<mapsize;i++)
if ((bf[i>>3]>>(i & 7)) & 1) map_coord[i].flags|=MC_DISCLOSED; if ((bf[i>>3]>>(i & 7)) & 1) map_coord[i].flags|=MC_DISCLOSED;
load_map_description(fsta); load_map_description(fsta);
while (temp_storage_read(&i,sizeof(i),fsta) && i > 0 && i<=mapsize*4) while (temp_storage_read(&i,sizeof(i),fsta) && i >= 0 && i<=mapsize*4)
if (temp_storage_read(map_sides+i,1*sizeof(TSTENA),fsta)!=sizeof(TSTENA)) goto err; if (temp_storage_read(map_sides+i,1*sizeof(TSTENA),fsta)!=sizeof(TSTENA)) goto err;
while (temp_storage_read(&i,sizeof(i),fsta) && i >0 && i<=mapsize) while (temp_storage_read(&i,sizeof(i),fsta) && i >= 0 && i<=mapsize)
if (temp_storage_read(map_sectors+i,1*sizeof(TSECTOR),fsta)!=sizeof(TSECTOR)) goto err; if (temp_storage_read(map_sectors+i,1*sizeof(TSECTOR),fsta)!=sizeof(TSECTOR)) goto err;
if (reset_mobiles) //reloads mobiles if flag present if (reset_mobiles) //reloads mobiles if flag present
{ {

View file

@ -705,7 +705,7 @@ void wire_end_game()
for(i=0;i<MAX_MOBS;i++) if (mobs[i].vlajky & MOB_LIVE) mobs[i].vlajky&=~MOB_IN_BATTLE; for(i=0;i<MAX_MOBS;i++) if (mobs[i].vlajky & MOB_LIVE) mobs[i].vlajky&=~MOB_IN_BATTLE;
for (int i = 0; i < POCET_POSTAV; ++i) { for (int i = 0; i < POCET_POSTAV; ++i) {
if (postavy[i].used && postavy[i].inmaphash != current_map_hash) { if (postavy[i].used && postavy[i].inmaphash != current_map_hash && postavy[i].lives) {
const char *mname = find_map_from_hash(postavy[i].inmaphash); const char *mname = find_map_from_hash(postavy[i].inmaphash);
if (mname != NULL) { if (mname != NULL) {
cur_group = postavy[i].groupnum; cur_group = postavy[i].groupnum;