diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index 637b7579b..cee286338 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -148,6 +148,7 @@ GameController::~GameController() delete *iter; } gameView->PauseRendererThread(); + commandInterface->RemoveComponents(); gameView->CloseActiveWindow(); delete gameView; commandInterface.reset(); diff --git a/src/lua/CommandInterface.h b/src/lua/CommandInterface.h index 84bf4d291..f5105549f 100644 --- a/src/lua/CommandInterface.h +++ b/src/lua/CommandInterface.h @@ -57,6 +57,7 @@ public: ValueType testType(String word); void SetToolIndex(ByteString identifier, std::optional index); + void RemoveComponents(); static CommandInterfacePtr Create(GameController *newGameController, GameModel *newGameModel); }; diff --git a/src/lua/LuaScriptInterface.cpp b/src/lua/LuaScriptInterface.cpp index 5868ee99b..225d686ba 100644 --- a/src/lua/LuaScriptInterface.cpp +++ b/src/lua/LuaScriptInterface.cpp @@ -218,6 +218,18 @@ void CommandInterface::SetToolIndex(ByteString identifier, std::optional in LuaTools::SetToolIndex(lsi->L, identifier, index); } +void CommandInterface::RemoveComponents() +{ + auto *lsi = static_cast(this); + for (auto &[ component, ref ] : lsi->grabbedComponents) + { + lsi->window->RemoveComponent(component->GetComponent()); + ref.Clear(); + component->owner_ref = ref; + component->SetParentWindow(nullptr); + } +} + void LuaGetProperty(lua_State *L, StructProperty property, intptr_t propertyAddress) { switch (property.Type) @@ -731,16 +743,7 @@ String CommandInterface::FormatCommand(String command) return highlight(command); } -LuaScriptInterface::~LuaScriptInterface() -{ - for (auto &[ component, ref ] : grabbedComponents) - { - window->RemoveComponent(component->GetComponent()); - ref.Clear(); - component->owner_ref = ref; - component->SetParentWindow(nullptr); - } -} +LuaScriptInterface::~LuaScriptInterface() = default; void tpt_lua_pushByteString(lua_State *L, const ByteString &str) { diff --git a/src/lua/PlainCommandInterface.cpp b/src/lua/PlainCommandInterface.cpp index 3f29f7925..94c7141f6 100644 --- a/src/lua/PlainCommandInterface.cpp +++ b/src/lua/PlainCommandInterface.cpp @@ -41,3 +41,7 @@ String CommandInterface::FormatCommand(String command) void CommandInterface::SetToolIndex(ByteString identifier, std::optional index) { } + +void CommandInterface::RemoveComponents() +{ +}