Merge branch 'fix_ui_crashes' into 'master'

Another day, another UI crash fix

See merge request OpenMW/openmw!3949
fix-osga-rotate-wildly
psi29a 10 months ago
commit 5d669f0470

@ -99,15 +99,6 @@ namespace LuaUi
element->create(depth + 1); element->create(depth + 1);
WidgetExtension* root = element->mRoot; WidgetExtension* root = element->mRoot;
assert(root); assert(root);
WidgetExtension* parent = root->getParent();
if (parent)
{
auto children = parent->children();
std::erase(children, root);
parent->setChildren(children);
root->widget()->detachFromWidget();
}
root->updateCoord();
return root; return root;
} }
@ -313,9 +304,8 @@ namespace LuaUi
{ {
if (mState != Destroyed) if (mState != Destroyed)
{ {
if (mState != New) if (mRoot != nullptr)
{ {
assert(mRoot);
destroyRoot(mRoot); destroyRoot(mRoot);
mRoot = nullptr; mRoot = nullptr;
} }

@ -100,6 +100,8 @@ namespace LuaUi
void WidgetExtension::attach(WidgetExtension* ext) void WidgetExtension::attach(WidgetExtension* ext)
{ {
if (ext->mParent != this)
ext->detachFromParent();
ext->mParent = this; ext->mParent = this;
ext->mTemplateChild = false; ext->mTemplateChild = false;
ext->widget()->attachToWidget(mSlot->widget()); ext->widget()->attachToWidget(mSlot->widget());
@ -114,7 +116,13 @@ namespace LuaUi
void WidgetExtension::detachFromParent() void WidgetExtension::detachFromParent()
{ {
if (mParent)
{
auto children = mParent->children();
std::erase(children, this);
mParent->setChildren(children);
mParent = nullptr; mParent = nullptr;
}
widget()->detachFromWidget(); widget()->detachFromWidget();
} }

Loading…
Cancel
Save