From 581585a47cdee3d29bcfb3f78ba8c5f4360cb88c Mon Sep 17 00:00:00 2001 From: smallmodel <15067410+smallmodel@users.noreply.github.com> Date: Tue, 15 Oct 2024 20:52:53 +0200 Subject: [PATCH] Prevent clearing the event command list if the event system is not initialized This fixes the issue where the game could crash (especially in optimized release) due to a memory corruption, because the event command list was deconstructed earlier --- code/fgame/scriptmaster.cpp | 7 +++++++ code/qcommon/listener.cpp | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/code/fgame/scriptmaster.cpp b/code/fgame/scriptmaster.cpp index 71fbc3c7..ce3fa48e 100644 --- a/code/fgame/scriptmaster.cpp +++ b/code/fgame/scriptmaster.cpp @@ -533,6 +533,13 @@ void ScriptMaster::InitConstStrings(void) AddString(ConstStrings[i]); } + if (!Listener::EventSystemStarted) { + // Added in OPM + // This usually means the game module is getting destroyed + // most often, the event command list has been destroyed earlier + return; + } + Event::normalCommandList.clear(); Event::returnCommandList.clear(); Event::getterCommandList.clear(); diff --git a/code/qcommon/listener.cpp b/code/qcommon/listener.cpp index 4b88f2b5..8d744950 100644 --- a/code/qcommon/listener.cpp +++ b/code/qcommon/listener.cpp @@ -612,6 +612,12 @@ void L_ShutdownEvents(void) Event::commandList.clear(); Event::eventDefList.clear(); +#ifdef WITH_SCRIPT_ENGINE + Event::normalCommandList.clear(); + Event::returnCommandList.clear(); + Event::getterCommandList.clear(); + Event::setterCommandList.clear(); +#endif Listener::EventSystemStarted = false; }