mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-29 02:40:47 +02:00
Fix crash on exit while there are Lua components visible
Broken since02b679aec3
and extremely similar to74386631e0
, 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:
@@ -148,6 +148,7 @@ GameController::~GameController()
|
||||
delete *iter;
|
||||
}
|
||||
gameView->PauseRendererThread();
|
||||
commandInterface->RemoveComponents();
|
||||
gameView->CloseActiveWindow();
|
||||
delete gameView;
|
||||
commandInterface.reset();
|
||||
|
@@ -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);
|
||||
};
|
||||
|
@@ -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)
|
||||
{
|
||||
|
@@ -41,3 +41,7 @@ String CommandInterface::FormatCommand(String command)
|
||||
void CommandInterface::SetToolIndex(ByteString identifier, std::optional<int> index)
|
||||
{
|
||||
}
|
||||
|
||||
void CommandInterface::RemoveComponents()
|
||||
{
|
||||
}
|
||||
|
Reference in New Issue
Block a user