diff --git a/components/lua_ui/element.cpp b/components/lua_ui/element.cpp index b491acb7b3..9d45f6ed7f 100644 --- a/components/lua_ui/element.cpp +++ b/components/lua_ui/element.cpp @@ -313,11 +313,14 @@ namespace LuaUi { if (mState != Destroyed) { - destroyRoot(mRoot); - mRoot = nullptr; if (mState != New) - mLayout = sol::make_object(mLayout.lua_state(), sol::nil); - mState = Destroyed; + { + assert(mRoot); + destroyRoot(mRoot); + mRoot = nullptr; + } + mLayout = sol::make_object(mLayout.lua_state(), sol::nil); } + mState = Destroyed; } }