diff --git a/src/imvue.cpp b/src/imvue.cpp index ed7a780..ad0f038 100644 --- a/src/imvue.cpp +++ b/src/imvue.cpp @@ -371,13 +371,18 @@ namespace ImVue { void Component::configure(rapidxml::xml_node<>* node, Context* ctx, ScriptState::Context* sctx, Element* parent) { Context* child = newChildContext(ctx); - child->root = this; - if(child->script) { - child->script->initialize(mData); - child->script->lifecycleCallback(ScriptState::BEFORE_CREATE); - } + try { + child->root = this; + if(child->script) { + child->script->initialize(mData); + child->script->lifecycleCallback(ScriptState::BEFORE_CREATE); + } - mScriptState = ctx->script; + mScriptState = ctx->script; + } catch(...) { + delete child; + throw; + } Element::configure(node, child, sctx, parent); if(mConfigured) { fireCallback(ScriptState::CREATED); diff --git a/src/imvue_element.cpp b/src/imvue_element.cpp index ab919f8..8575717 100644 --- a/src/imvue_element.cpp +++ b/src/imvue_element.cpp @@ -516,7 +516,7 @@ namespace ImVue { void Element::fireCallback(ScriptState::LifecycleCallbackType cb, bool schedule) { - if(!mCtx->script) { + if(!mCtx || !mCtx->script) { return; } diff --git a/tests/resources/bad.imv b/tests/resources/bad.imv new file mode 100644 index 0000000..192c6a7 --- /dev/null +++ b/tests/resources/bad.imv @@ -0,0 +1,18 @@ + + + diff --git a/tests/resources/components.xml b/tests/resources/components.xml index a9ead3d..53dedb0 100644 --- a/tests/resources/components.xml +++ b/tests/resources/components.xml @@ -3,7 +3,10 @@ current count {{ self.count }} -