From 5d219b2f7e8ce196486c225e971f76ceab5538c5 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 29 May 2013 23:17:00 +0300 Subject: [PATCH] Restore parent to 0 if an exception occurs while setting things up This prevents an inconsistent state from forming if something goes wrong. --- source/widget.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/source/widget.cpp b/source/widget.cpp index 9dbd9da..bbd2e88 100644 --- a/source/widget.cpp +++ b/source/widget.cpp @@ -70,10 +70,20 @@ void Widget::set_parent(Container *p) throw hierarchy_error("widget already parented"); else if(p==parent) return; - parent = p; - on_reparent(); - update_style(); + try + { + parent = p; + + on_reparent(); + update_style(); + } + catch(...) + { + // The container has not yet added the widget as its child + parent = 0; + throw; + } } void Widget::set_style(const string &s) -- 2.43.0