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:
commit
2b9f962f7c
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
};
|
||||
|
@ -239,6 +239,7 @@
|
||||
|
||||
---
|
||||
-- Access or replace the element's layout
|
||||
-- Note: Is reset to `nil` on `destroy`
|
||||
-- @field [parent=#Element] #Layout layout
|
||||
|
||||
---
|
||||
|
Loading…
Reference in New Issue
Block a user