diff --git a/code/fgame/gamescript.cpp b/code/fgame/gamescript.cpp index 831f1830..fe5999c0 100644 --- a/code/fgame/gamescript.cpp +++ b/code/fgame/gamescript.cpp @@ -1,6 +1,6 @@ /* =========================================================================== -Copyright (C) 2024 the OpenMoHAA team +Copyright (C) 2025 the OpenMoHAA team This file is part of OpenMoHAA source code. @@ -686,10 +686,17 @@ void GameScript::ArchiveCodePos(Archiver& arc, unsigned char **codePos) void GameScript::Close(void) { + // Free up catch blocks for (int i = m_CatchBlocks.NumObjects(); i > 0; i--) { delete m_CatchBlocks.ObjectAt(i); } + // Added in OPM + // Free up allocated state scripts + for (int i = m_StateScripts.NumObjects(); i > 0; i--) { + delete m_StateScripts.ObjectAt(i); + } + m_CatchBlocks.FreeObjectList(); if (m_ProgToSource) { @@ -814,7 +821,11 @@ StateScript *GameScript::CreateCatchStateScript(unsigned char *try_begin_code_po StateScript *GameScript::CreateSwitchStateScript(void) { - return new StateScript; + StateScript *stateScript = new StateScript; + + m_StateScripts.AddObject(stateScript); + + return stateScript; } StateScript *GameScript::GetCatchStateScript(unsigned char *in, unsigned char *& out) @@ -927,7 +938,8 @@ void ScriptThreadLabel::Execute(Listener *listener, Event *ev) const Execute(listener, *ev); } -void ScriptThreadLabel::Execute(Listener *pSelf, const SafePtr& listener, const SafePtr& param) const +void ScriptThreadLabel::Execute(Listener *pSelf, const SafePtr& listener, const SafePtr& param) + const { if (!m_Script) { return; diff --git a/code/fgame/gamescript.h b/code/fgame/gamescript.h index 23e85774..80af333b 100644 --- a/code/fgame/gamescript.h +++ b/code/fgame/gamescript.h @@ -1,6 +1,6 @@ /* =========================================================================== -Copyright (C) 2024 the OpenMoHAA team +Copyright (C) 2025 the OpenMoHAA team This file is part of OpenMoHAA source code. @@ -118,7 +118,8 @@ class GameScript : public AbstractScript { protected: // try/throw variable - Container m_CatchBlocks; + Container m_CatchBlocks; + Container m_StateScripts; public: // program variables