From dd1058c767b4aa9ecd9cb72062a93318b8aeb3b1 Mon Sep 17 00:00:00 2001 From: terminx Date: Sat, 29 Sep 2018 01:54:52 +0000 Subject: [PATCH] Actually fix savegame crash... probably. git-svn-id: https://svn.eduke32.com/eduke32@6987 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/duke3d/src/savegame.cpp | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/source/duke3d/src/savegame.cpp b/source/duke3d/src/savegame.cpp index 76f3cd56e..4d5ff96a3 100644 --- a/source/duke3d/src/savegame.cpp +++ b/source/duke3d/src/savegame.cpp @@ -1242,9 +1242,9 @@ static const dataspec_t svgm_script[] = { { DS_STRING, (void *)svgm_script_string, 0, 1 }, { DS_SAVEFN, (void *) &sv_preprojectilesave, 0, 1 }, - { DS_NOCHK, &savegame_projectiles, sizeof(savegame_projectiles), 1 }, + { DS_NOCHK, savegame_projectiles, sizeof(savegame_projectiles), 1 }, { DS_LOADFN, (void *) &sv_preprojectileload, 0, 1 }, - { DS_DYNAMIC|DS_CNT(savegame_projectilecnt), &savegame_projectiledata, sizeof(projectile_t), (intptr_t)&savegame_projectilecnt }, + { DS_CNT(savegame_projectilecnt), savegame_projectiledata, sizeof(projectile_t), (intptr_t)&savegame_projectilecnt }, { DS_SAVEFN, (void *) &sv_postprojectilesave, 0, 1 }, { DS_LOADFN, (void *) &sv_postprojectileload, 0, 1 }, { 0, &actor[0], sizeof(actor_t), MAXSPRITES }, @@ -1849,17 +1849,16 @@ static void sv_quoteload() static void sv_preprojectilesave() { savegame_projectilecnt = 0; + Bmemset(savegame_projectiles, 0, sizeof(savegame_projectiles)); - for (bssize_t i=0; i 0) + if (savegame_projectilecnt > 0) savegame_projectiledata = (projectile_t *) Xrealloc(savegame_projectiledata, sizeof(projectile_t) * savegame_projectilecnt); - int32_t cnt = 0; - - for (bssize_t i=0; i>3]&(1<<(i&7))) - cnt++; + savegame_projectilecnt++; } - if (savegame_projectiledata != NULL || cnt > 0) - savegame_projectiledata = (projectile_t *) Xrealloc(savegame_projectiledata, sizeof(projectile_t) * cnt); + if (savegame_projectilecnt > 0) + savegame_projectiledata = (projectile_t *) Xrealloc(savegame_projectiledata, sizeof(projectile_t) * savegame_projectilecnt); } static void sv_postprojectileload() { - int32_t cnt = 0; - - for (bssize_t i=0; i>3]&(1<<(i&7))) { @@ -1900,7 +1897,8 @@ static void sv_postprojectileload() Bmemcpy(g_tile[i].proj, &savegame_projectiledata[cnt++], sizeof(projectile_t)); } } -// DO_FREE_AND_NULL(ProjectileData); + + DO_FREE_AND_NULL(savegame_projectiledata); } static void sv_prequoteredef()