Fix savemapstate/loadmapstate (fixes a crash at shutdown, among other things)

git-svn-id: https://svn.eduke32.com/eduke32@4923 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2015-01-16 06:30:42 +00:00
parent b3358a90b2
commit bd27267b6b
3 changed files with 12 additions and 9 deletions

View file

@ -5432,7 +5432,10 @@ void G_SaveMapState(void)
map_t *mapinfo = &MapInfo[levelnum]; map_t *mapinfo = &MapInfo[levelnum];
if (mapinfo->savedstate == NULL) if (mapinfo->savedstate == NULL)
mapinfo->savedstate = (mapstate_t *)Xcalloc(1,sizeof(mapstate_t)); {
mapinfo->savedstate = (mapstate_t *) Xaligned_alloc(16, sizeof(mapstate_t));
Bmemset(mapinfo->savedstate, 0, sizeof(mapstate_t));
}
mapstate_t *save = mapinfo->savedstate; mapstate_t *save = mapinfo->savedstate;
@ -5513,13 +5516,13 @@ void G_SaveMapState(void)
if (aGameVars[i].dwFlags & GAMEVAR_PERPLAYER) if (aGameVars[i].dwFlags & GAMEVAR_PERPLAYER)
{ {
if (!save->vars[i]) if (!save->vars[i])
save->vars[i] = (intptr_t *)Xcalloc(MAXPLAYERS,sizeof(intptr_t)); save->vars[i] = (intptr_t *)Xaligned_alloc(16, MAXPLAYERS * sizeof(intptr_t));
Bmemcpy(&save->vars[i][0],&aGameVars[i].val.plValues[0],sizeof(intptr_t) * MAXPLAYERS); Bmemcpy(&save->vars[i][0],&aGameVars[i].val.plValues[0],sizeof(intptr_t) * MAXPLAYERS);
} }
else if (aGameVars[i].dwFlags & GAMEVAR_PERACTOR) else if (aGameVars[i].dwFlags & GAMEVAR_PERACTOR)
{ {
if (!save->vars[i]) if (!save->vars[i])
save->vars[i] = (intptr_t *)Xcalloc(MAXSPRITES,sizeof(intptr_t)); save->vars[i] = (intptr_t *)Xaligned_alloc(16, MAXSPRITES * sizeof(intptr_t));
Bmemcpy(&save->vars[i][0],&aGameVars[i].val.plValues[0],sizeof(intptr_t) * MAXSPRITES); Bmemcpy(&save->vars[i][0],&aGameVars[i].val.plValues[0],sizeof(intptr_t) * MAXSPRITES);
} }
else save->vars[i] = (intptr_t *)aGameVars[i].val.lValue; else save->vars[i] = (intptr_t *)aGameVars[i].val.lValue;

View file

@ -1417,7 +1417,7 @@ end_vol4a:
for (i=0; i<(MAXVOLUMES*MAXLEVELS); i++) for (i=0; i<(MAXVOLUMES*MAXLEVELS); i++)
if (MapInfo[i].savedstate) if (MapInfo[i].savedstate)
{ {
Bfree(MapInfo[i].savedstate); Baligned_free(MapInfo[i].savedstate);
MapInfo[i].savedstate = NULL; MapInfo[i].savedstate = NULL;
} }
@ -2020,12 +2020,12 @@ void G_FreeMapState(int32_t mapnum)
if (aGameVars[j].dwFlags & (GAMEVAR_PERPLAYER|GAMEVAR_PERACTOR)) if (aGameVars[j].dwFlags & (GAMEVAR_PERPLAYER|GAMEVAR_PERACTOR))
{ {
if (mapinfo->savedstate->vars[j]) if (mapinfo->savedstate->vars[j])
Bfree(mapinfo->savedstate->vars[j]); Baligned_free(mapinfo->savedstate->vars[j]);
} }
} }
#else #else
Bfree(mapinfo->savedstate->savecode); Bfree(mapinfo->savedstate->savecode);
#endif #endif
Bfree(mapinfo->savedstate); Baligned_free(mapinfo->savedstate);
mapinfo->savedstate = NULL; mapinfo->savedstate = NULL;
} }

View file

@ -79,10 +79,10 @@ typedef struct {
actor_t actor[MAXSPRITES]; actor_t actor[MAXSPRITES];
playerspawn_t g_playerSpawnPoints[MAXPLAYERS]; playerspawn_t g_playerSpawnPoints[MAXPLAYERS];
animwalltype animwall[MAXANIMWALLS]; animwalltype animwall[MAXANIMWALLS];
sectortype sector[MAXSECTORS]; tsectortype sector[MAXSECTORS];
spriteext_t spriteext[MAXSPRITES]; spriteext_t spriteext[MAXSPRITES];
spritetype sprite[MAXSPRITES]; tspritetype sprite[MAXSPRITES];
walltype wall[MAXWALLS]; twalltype wall[MAXWALLS];
#if !defined LUNATIC #if !defined LUNATIC
intptr_t *vars[MAXGAMEVARS]; intptr_t *vars[MAXGAMEVARS];
#else #else