From f4e70bfa75a595f288756bf49f6e741d2d3a6b8b32cf20d678882803bcaf0b18 Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Fri, 18 Apr 2025 03:41:06 -0400 Subject: [PATCH] I plumbed out ownership a bit and it hasn't crashed yet. --- dw/layout.cc | 27 ++++++++++++++------------- dw/layout.hh | 2 +- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/dw/layout.cc b/dw/layout.cc index aef5ec0..7186212 100644 --- a/dw/layout.cc +++ b/dw/layout.cc @@ -362,7 +362,7 @@ void Layout::detachWidget (Widget *widget) it->unref (); } -void Layout::addWidget (Widget *widget) +void Layout::addWidget (std::unique_ptr< Widget > widget) { if (topLevel) { MSG_WARN("widget already set\n"); @@ -372,22 +372,21 @@ void Layout::addWidget (Widget *widget) // The toplevel widget always establishes a stacking context. It could // already be set in Widget::setStyle(). if (widget->stackingContextMgr == NULL && IMPL_POS) { - widget->stackingContextMgr = new StackingContextMgr (widget); - DBG_OBJ_ASSOC (widget, widget->stackingContextMgr); - widget->stackingContextWidget = widget; + widget->stackingContextMgr = new StackingContextMgr (widget.get()); + DBG_OBJ_ASSOC (widget.get(), widget->stackingContextMgr); + widget->stackingContextWidget = widget.get(); } - std::unique_ptr< Widget > widget_unique; - widget_unique.reset( widget ); - topLevel = std::move( widget_unique ); - widget->layout = this; - widget->container = NULL; - DBG_OBJ_SET_PTR_O (widget, "container", widget->container); + Widget *widget_p= widget.get(); + topLevel = std::move( widget ); + widget_p->layout = this; + widget_p->container = NULL; + DBG_OBJ_SET_PTR_O (widget_p, "container", widget_p->container); queueResizeList->clear (); - widget->notifySetAsTopLevel (); + widget_p->notifySetAsTopLevel (); - findtextState.setWidget (widget); + findtextState.setWidget (widget_p); canvasHeightGreater = false; DBG_OBJ_SET_SYM ("canvasHeightGreater", @@ -435,7 +434,9 @@ void Layout::setWidget (Widget *widget) topLevel.reset(); } textZone->zoneFree (); - addWidget (widget); + std::unique_ptr< Widget > widget_unique; + widget_unique.reset( widget ); + addWidget (std::move( widget_unique )); updateCursor (); diff --git a/dw/layout.hh b/dw/layout.hh index 757ce3a..a47ee2b 100644 --- a/dw/layout.hh +++ b/dw/layout.hh @@ -282,7 +282,7 @@ public: lout::misc::ZoneAllocator *textZone; - void addWidget (Widget *widget); + void addWidget (std::unique_ptr< Widget > widget); void setWidget (Widget *widget); void attachView (View *view);