mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-28 10:20:04 +02:00
Fix missing delete commandInterface, fix gc issue with LuaComponent/LuaWindow
lua_close wasn't being called at all before due to the delete commandInterface being missing. With it there, the lua gc could delete the LuaComponent before the LuaWindow. Make sure if that happens, it tells the parent LuaWindow it's already been gced
This commit is contained in:
@@ -161,6 +161,7 @@ GameController::~GameController()
|
||||
{
|
||||
delete gameView;
|
||||
}
|
||||
delete commandInterface;
|
||||
}
|
||||
|
||||
void GameController::HistoryRestore()
|
||||
|
@@ -4,6 +4,7 @@
|
||||
#include "LuaComponent.h"
|
||||
|
||||
#include "LuaScriptInterface.h"
|
||||
#include "LuaWindow.h"
|
||||
|
||||
#include "gui/interface/Component.h"
|
||||
#include "gui/interface/Window.h"
|
||||
@@ -83,6 +84,9 @@ int LuaComponent::visible(lua_State * l)
|
||||
|
||||
LuaComponent::~LuaComponent()
|
||||
{
|
||||
if (parent)
|
||||
parent->ClearRef(this);
|
||||
|
||||
if (component)
|
||||
{
|
||||
if (component->GetParentWindow())
|
||||
|
@@ -9,6 +9,7 @@ namespace ui
|
||||
}
|
||||
|
||||
class LuaScriptInterface;
|
||||
class LuaWindow;
|
||||
|
||||
class LuaComponentCallback : public LuaSmartRef
|
||||
{
|
||||
@@ -22,6 +23,8 @@ class LuaComponent
|
||||
protected:
|
||||
ui::Component * component;
|
||||
lua_State * l;
|
||||
LuaWindow * parent = nullptr;
|
||||
|
||||
int position(lua_State * l);
|
||||
int size(lua_State * l);
|
||||
int visible(lua_State * l);
|
||||
@@ -30,6 +33,7 @@ public:
|
||||
int owner_ref;
|
||||
|
||||
ui::Component * GetComponent() { return component; }
|
||||
void SetParentWindow(LuaWindow *parent) { this->parent = parent; }
|
||||
LuaComponent(lua_State * l);
|
||||
~LuaComponent();
|
||||
};
|
||||
|
@@ -136,6 +136,7 @@ int LuaWindow::addComponent(lua_State * l)
|
||||
it->first->owner_ref = it->second;
|
||||
}
|
||||
window->AddComponent(luaComponent->GetComponent());
|
||||
luaComponent->SetParentWindow(this);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -168,6 +169,7 @@ int LuaWindow::removeComponent(lua_State * l)
|
||||
it->second.Clear();
|
||||
it->first->owner_ref = it->second;
|
||||
grabbed_components.erase(it);
|
||||
luaComponent->SetParentWindow(nullptr);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@@ -485,6 +487,17 @@ int LuaWindow::onKeyRelease(lua_State * l)
|
||||
return onKeyReleaseFunction.CheckAndAssignArg1(l);
|
||||
}
|
||||
|
||||
void LuaWindow::ClearRef(LuaComponent *luaComponent)
|
||||
{
|
||||
auto it = grabbed_components.find(luaComponent);
|
||||
if (it != grabbed_components.end())
|
||||
{
|
||||
window->RemoveComponent(luaComponent->GetComponent());
|
||||
it->second.Clear();
|
||||
it->first->owner_ref = it->second;
|
||||
grabbed_components.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
LuaWindow::~LuaWindow()
|
||||
{
|
||||
|
@@ -75,6 +75,8 @@ public:
|
||||
static Luna<LuaWindow>::RegType methods[];
|
||||
|
||||
ui::Window * GetWindow() { return window; }
|
||||
void ClearRef(LuaComponent *luaComponent);
|
||||
|
||||
LuaWindow(lua_State * l);
|
||||
~LuaWindow();
|
||||
};
|
||||
|
Reference in New Issue
Block a user