Fix crash when recording demo, stooping it, going to title screen, and exiting.

A macro MAYBE_FCLOSE_AND_NULL(fileptr) is introduced in compat.h that does
what it says.

git-svn-id: https://svn.eduke32.com/eduke32@2995 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2012-09-05 17:25:31 +00:00
parent 667de29e01
commit 9311432cbf
3 changed files with 12 additions and 7 deletions

View file

@ -650,5 +650,9 @@ char *Bstrupr(char *);
} }
#endif #endif
#define MAYBE_FCLOSE_AND_NULL(fileptr) do { \
if (fileptr) { Bfclose(fileptr); fileptr=NULL; } \
} while (0)
#endif // __compat_h__ #endif // __compat_h__

View file

@ -193,7 +193,7 @@ void G_OpenDemoWrite(void)
if (g_demo_filePtr == NULL) if (g_demo_filePtr == NULL)
break; break;
Bfclose(g_demo_filePtr); MAYBE_FCLOSE_AND_NULL(g_demo_filePtr);
} }
while (1); while (1);
@ -205,7 +205,7 @@ void G_OpenDemoWrite(void)
demorec_synccompress_cvar|(demorec_seeds_cvar<<1)); demorec_synccompress_cvar|(demorec_seeds_cvar<<1));
if (i) if (i)
{ {
Bfclose(g_demo_filePtr), g_demo_filePtr=NULL; MAYBE_FCLOSE_AND_NULL(g_demo_filePtr);
error_wopen_demo: error_wopen_demo:
Bstrcpy(ScriptQuotes[QUOTE_RESERVED4], "FAILED STARTING DEMO RECORDING. SEE OSD FOR DETAILS."); Bstrcpy(ScriptQuotes[QUOTE_RESERVED4], "FAILED STARTING DEMO RECORDING. SEE OSD FOR DETAILS.");
P_DoQuote(QUOTE_RESERVED4, g_player[myconnectindex].ps); P_DoQuote(QUOTE_RESERVED4, g_player[myconnectindex].ps);
@ -292,7 +292,7 @@ void G_CloseDemoWrite(void)
fwrite(&g_demo_cnt, sizeof(g_demo_cnt), 1, g_demo_filePtr); fwrite(&g_demo_cnt, sizeof(g_demo_cnt), 1, g_demo_filePtr);
ud.recstat = ud.m_recstat = 0; ud.recstat = ud.m_recstat = 0;
fclose(g_demo_filePtr); MAYBE_FCLOSE_AND_NULL(g_demo_filePtr);
sv_freemem(); sv_freemem();

View file

@ -2077,11 +2077,12 @@ void G_GameExit(const char *msg)
#endif #endif
if (*msg != 0) g_player[myconnectindex].ps->palette = BASEPAL; if (*msg != 0) g_player[myconnectindex].ps->palette = BASEPAL;
if (ud.recstat == 1) G_CloseDemoWrite(); if (ud.recstat == 1)
G_CloseDemoWrite();
else if (ud.recstat == 2) else if (ud.recstat == 2)
{ MAYBE_FCLOSE_AND_NULL(g_demo_filePtr);
if (g_demo_filePtr) fclose(g_demo_filePtr); // JBF: fixes crash on demo playback
} // JBF: fixes crash on demo playback // PK: modified from original
if (!g_quickExit) if (!g_quickExit)
{ {