More NULL handling for gamedata

Partial duplicate of MR 1010, but 1) wanted to guarantee no merge conflicts before I forgot and 2) I added things in previous commits which needed stronger guarding
This commit is contained in:
toaster 2023-03-03 13:59:59 +00:00
parent 1f144c3106
commit db52c22a83
4 changed files with 11 additions and 5 deletions

View file

@ -977,7 +977,7 @@ void D_ClearState(void)
cursongcredit.def = NULL;
if (gamedata->deferredsave)
if (gamedata && gamedata->deferredsave)
G_SaveGameData(true);
G_SetGamestate(GS_NULL);

View file

@ -4558,11 +4558,11 @@ void G_SaveGameData(boolean dirty)
UINT8 btemp;
savebuffer_t save = {0};
gamedata->deferredsave = false;
if (!gamedata->loaded)
if (gamedata == NULL || !gamedata->loaded)
return; // If never loaded (-nodata), don't save
gamedata->deferredsave = false;
if (usedCheats)
{
#ifdef DEVELOP

View file

@ -1090,6 +1090,12 @@ boolean M_UpdateUnlockablesAndExtraEmblems(boolean loud)
INT32 i;
UINT8 response = 0;
if (!gamedata)
{
// Don't attempt to write/check anything.
return false;
}
if (!loud)
{
// Just in case they aren't to sync

View file

@ -633,7 +633,7 @@ void P_Ticker(boolean run)
// TODO would this be laggy with more conditions in play...
if ((!demo.playback && M_UpdateUnlockablesAndExtraEmblems(true))
|| gamedata->deferredsave)
|| (gamedata && gamedata->deferredsave))
G_SaveGameData(true);
}