Fix crash on exit while there are Lua components visible

Broken since 02b679aec3 and extremely similar to 74386631e0, which makes sure that both LSI and GameView are alive when destroying Lua windows: in this case, they both need to be alive when destroying components attached to the main window. Also, the main window has to exist still.
This commit is contained in:
Tamás Bálint Misius
2025-01-05 10:36:49 +01:00
parent f7753ff76f
commit 3fe5dcc447
4 changed files with 19 additions and 10 deletions

View File

@@ -148,6 +148,7 @@ GameController::~GameController()
delete *iter;
}
gameView->PauseRendererThread();
commandInterface->RemoveComponents();
gameView->CloseActiveWindow();
delete gameView;
commandInterface.reset();

View File

@@ -57,6 +57,7 @@ public:
ValueType testType(String word);
void SetToolIndex(ByteString identifier, std::optional<int> index);
void RemoveComponents();
static CommandInterfacePtr Create(GameController *newGameController, GameModel *newGameModel);
};

View File

@@ -218,6 +218,18 @@ void CommandInterface::SetToolIndex(ByteString identifier, std::optional<int> in
LuaTools::SetToolIndex(lsi->L, identifier, index);
}
void CommandInterface::RemoveComponents()
{
auto *lsi = static_cast<LuaScriptInterface *>(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)
{

View File

@@ -41,3 +41,7 @@ String CommandInterface::FormatCommand(String command)
void CommandInterface::SetToolIndex(ByteString identifier, std::optional<int> index)
{
}
void CommandInterface::RemoveComponents()
{
}