mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-09-01 20:12:50 +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;
|
delete *iter;
|
||||||
}
|
}
|
||||||
gameView->PauseRendererThread();
|
gameView->PauseRendererThread();
|
||||||
|
commandInterface->RemoveComponents();
|
||||||
gameView->CloseActiveWindow();
|
gameView->CloseActiveWindow();
|
||||||
delete gameView;
|
delete gameView;
|
||||||
commandInterface.reset();
|
commandInterface.reset();
|
||||||
|
@@ -57,6 +57,7 @@ public:
|
|||||||
ValueType testType(String word);
|
ValueType testType(String word);
|
||||||
|
|
||||||
void SetToolIndex(ByteString identifier, std::optional<int> index);
|
void SetToolIndex(ByteString identifier, std::optional<int> index);
|
||||||
|
void RemoveComponents();
|
||||||
|
|
||||||
static CommandInterfacePtr Create(GameController *newGameController, GameModel *newGameModel);
|
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);
|
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)
|
void LuaGetProperty(lua_State *L, StructProperty property, intptr_t propertyAddress)
|
||||||
{
|
{
|
||||||
switch (property.Type)
|
switch (property.Type)
|
||||||
@@ -731,16 +743,7 @@ String CommandInterface::FormatCommand(String command)
|
|||||||
return highlight(command);
|
return highlight(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
LuaScriptInterface::~LuaScriptInterface()
|
LuaScriptInterface::~LuaScriptInterface() = default;
|
||||||
{
|
|
||||||
for (auto &[ component, ref ] : grabbedComponents)
|
|
||||||
{
|
|
||||||
window->RemoveComponent(component->GetComponent());
|
|
||||||
ref.Clear();
|
|
||||||
component->owner_ref = ref;
|
|
||||||
component->SetParentWindow(nullptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void tpt_lua_pushByteString(lua_State *L, const ByteString &str)
|
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::SetToolIndex(ByteString identifier, std::optional<int> index)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CommandInterface::RemoveComponents()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user