From bd27267b6b67fabf7961dbd6546d1c86e493203b Mon Sep 17 00:00:00 2001 From: terminx Date: Fri, 16 Jan 2015 06:30:42 +0000 Subject: [PATCH] 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 --- polymer/eduke32/source/gameexec.c | 9 ++++++--- polymer/eduke32/source/premap.c | 6 +++--- polymer/eduke32/source/sector.h | 6 +++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/polymer/eduke32/source/gameexec.c b/polymer/eduke32/source/gameexec.c index f2bfa8f87..5836084be 100644 --- a/polymer/eduke32/source/gameexec.c +++ b/polymer/eduke32/source/gameexec.c @@ -5432,7 +5432,10 @@ void G_SaveMapState(void) map_t *mapinfo = &MapInfo[levelnum]; 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; @@ -5513,13 +5516,13 @@ void G_SaveMapState(void) if (aGameVars[i].dwFlags & GAMEVAR_PERPLAYER) { 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); } else if (aGameVars[i].dwFlags & GAMEVAR_PERACTOR) { 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); } else save->vars[i] = (intptr_t *)aGameVars[i].val.lValue; diff --git a/polymer/eduke32/source/premap.c b/polymer/eduke32/source/premap.c index 8e54da83d..1d653c318 100644 --- a/polymer/eduke32/source/premap.c +++ b/polymer/eduke32/source/premap.c @@ -1417,7 +1417,7 @@ end_vol4a: for (i=0; i<(MAXVOLUMES*MAXLEVELS); i++) if (MapInfo[i].savedstate) { - Bfree(MapInfo[i].savedstate); + Baligned_free(MapInfo[i].savedstate); MapInfo[i].savedstate = NULL; } @@ -2020,12 +2020,12 @@ void G_FreeMapState(int32_t mapnum) if (aGameVars[j].dwFlags & (GAMEVAR_PERPLAYER|GAMEVAR_PERACTOR)) { if (mapinfo->savedstate->vars[j]) - Bfree(mapinfo->savedstate->vars[j]); + Baligned_free(mapinfo->savedstate->vars[j]); } } #else Bfree(mapinfo->savedstate->savecode); #endif - Bfree(mapinfo->savedstate); + Baligned_free(mapinfo->savedstate); mapinfo->savedstate = NULL; } diff --git a/polymer/eduke32/source/sector.h b/polymer/eduke32/source/sector.h index 5ba52dd8e..e92065b8c 100644 --- a/polymer/eduke32/source/sector.h +++ b/polymer/eduke32/source/sector.h @@ -79,10 +79,10 @@ typedef struct { actor_t actor[MAXSPRITES]; playerspawn_t g_playerSpawnPoints[MAXPLAYERS]; animwalltype animwall[MAXANIMWALLS]; - sectortype sector[MAXSECTORS]; + tsectortype sector[MAXSECTORS]; spriteext_t spriteext[MAXSPRITES]; - spritetype sprite[MAXSPRITES]; - walltype wall[MAXWALLS]; + tspritetype sprite[MAXSPRITES]; + twalltype wall[MAXWALLS]; #if !defined LUNATIC intptr_t *vars[MAXGAMEVARS]; #else