1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-01 03:21:41 +00:00

Merge branch 'minimal_element_leak' into 'master'

Minimal solution to UI Element leak

See merge request OpenMW/openmw!2770
This commit is contained in:
psi29a 2023-02-26 14:57:30 +00:00
commit 2b9f962f7c
3 changed files with 13 additions and 9 deletions

View File

@ -189,8 +189,8 @@ namespace LuaUi
assert(!mRoot);
if (!mRoot)
{
mRoot = createWidget(mLayout, 0);
mLayer = setLayer(mRoot, mLayout);
mRoot = createWidget(layout(), 0);
mLayer = setLayer(mRoot, layout());
updateAttachment();
}
}
@ -199,16 +199,16 @@ namespace LuaUi
{
if (mRoot && mUpdate)
{
if (mRoot->widget()->getTypeName() != widgetType(mLayout))
if (mRoot->widget()->getTypeName() != widgetType(layout()))
{
destroyWidget(mRoot);
mRoot = createWidget(mLayout, 0);
mRoot = createWidget(layout(), 0);
}
else
{
updateWidget(mRoot, mLayout, 0);
updateWidget(mRoot, layout(), 0);
}
mLayer = setLayer(mRoot, mLayout);
mLayer = setLayer(mRoot, layout());
updateAttachment();
}
mUpdate = false;
@ -216,9 +216,11 @@ namespace LuaUi
void Element::destroy()
{
if (mRoot)
destroyWidget(mRoot);
if (!mRoot)
return;
destroyWidget(mRoot);
mRoot = nullptr;
mLayout = sol::make_object(mLayout.lua_state(), sol::nil);
sAllElements.erase(this);
}

View File

@ -18,7 +18,7 @@ namespace LuaUi
WidgetExtension* mRoot;
WidgetExtension* mAttachedTo;
sol::table mLayout;
sol::object mLayout;
std::string mLayer;
bool mUpdate;
bool mDestroy;
@ -36,6 +36,7 @@ namespace LuaUi
private:
Element(sol::table layout);
sol::table layout() { return mLayout.as<sol::table>(); }
static std::map<Element*, std::shared_ptr<Element>> sAllElements;
void updateAttachment();
};

View File

@ -239,6 +239,7 @@
---
-- Access or replace the element's layout
-- Note: Is reset to `nil` on `destroy`
-- @field [parent=#Element] #Layout layout
---