From 2d2faf124767533d1d594b753b129d9bf547b5b7 Mon Sep 17 00:00:00 2001 From: Steven Fuller Date: Sun, 18 May 2008 05:08:17 -0700 Subject: [PATCH] Worked around a crash during level reloads. Global state in bh_marin.c isn't being deinitialized, and this was causing some code to incorrectly execute during a level restart. Said code has been commented out, as it appears to have been previously disabled. Improved the deinitialization in pheromon.c to make similar crashes more obvious. --- src/avp/bh_marin.c | 9 ++++++++- src/avp/pheromon.c | 42 +++++++++++++++++++++++++++++++++++------- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/src/avp/bh_marin.c b/src/avp/bh_marin.c index 8befd1c..7db60df 100644 --- a/src/avp/bh_marin.c +++ b/src/avp/bh_marin.c @@ -13719,6 +13719,12 @@ void GetPointToFaceMarineTowards(STRATEGYBLOCK *sbPtr,VECTORCH *output) { return; } + // SBF - 20080518 - commented out - this block of code is a NO-OP + // due to the aliased targetModule variable. This code might have + // been disabled intentionally? In any case, disabling this code + // works around a crash in FarNPC_GetTargetAIModuleForMarineRespond + // during level reloads. +#if 0 // SBF - 20080518 - commented out if (NpcSquad.alertZone) { /* Might want to face towards trouble. */ if (sbPtr->containingModule->m_aimodule!=NpcSquad.alertZone) { @@ -13726,7 +13732,7 @@ void GetPointToFaceMarineTowards(STRATEGYBLOCK *sbPtr,VECTORCH *output) { targetModule = FarNPC_GetTargetAIModuleForMarineRespond(sbPtr); } } - + /* Did that work? */ if (targetModule) { @@ -13745,6 +13751,7 @@ void GetPointToFaceMarineTowards(STRATEGYBLOCK *sbPtr,VECTORCH *output) { } } +#endif // SBF - 20080518 - commented out AdjModuleRefPtr = sbPtr->containingModule->m_aimodule->m_link_ptrs; /* check if there is a module adjacency list */ diff --git a/src/avp/pheromon.c b/src/avp/pheromon.c index 4a04fa8..cb84b84 100644 --- a/src/avp/pheromon.c +++ b/src/avp/pheromon.c @@ -182,16 +182,44 @@ End of level clean up for pheromone system void CleanUpPheromoneSystem(void) { #if 1 - if (Pher_Player1) DeallocateMem(Pher_Player1); - if (Pher_Player2) DeallocateMem(Pher_Player2); - if (Pher_Ai1) DeallocateMem(Pher_Ai1); + if (Pher_Player1 != NULL) { + DeallocateMem(Pher_Player1); + Pher_Player1 = NULL; + } + if (Pher_Player2 != NULL) { + DeallocateMem(Pher_Player2); + Pher_Player2 = NULL; + } + if (Pher_Ai1 != NULL) { + DeallocateMem(Pher_Ai1); + Pher_Ai1 = NULL; + } + PherPl_ReadBuf = NULL; + PherPl_WriteBuf = NULL; + PherAi_Buf = NULL; #endif #if SUPER_PHEROMONE_SYSTEM - if (Pher_Aliens1) DeallocateMem(Pher_Aliens1); - if (Pher_Aliens2) DeallocateMem(Pher_Aliens2); - if (Pher_Marines1) DeallocateMem(Pher_Marines1); - if (Pher_Marines2) DeallocateMem(Pher_Marines2); + if (Pher_Aliens1 != NULL) { + DeallocateMem(Pher_Aliens1); + Pher_Aliens1 = NULL; + } + if (Pher_Aliens2 != NULL) { + DeallocateMem(Pher_Aliens2); + Pher_Aliens2 = NULL; + } + if (Pher_Marines1 != NULL) { + DeallocateMem(Pher_Marines1); + Pher_Marines1 = NULL; + } + if (Pher_Marines2 != NULL) { + DeallocateMem(Pher_Marines2); + Pher_Marines2 = NULL; + } + PherAls_ReadBuf = NULL; + PherAls_WriteBuf = NULL; + PherMars_ReadBuf = NULL; + PherMars_WriteBuf = NULL; #endif }