I plumbed out ownership a bit and it hasn't crashed yet.

This commit is contained in:
2025-04-18 03:41:06 -04:00
parent fc9a191582
commit f4e70bfa75
2 changed files with 15 additions and 14 deletions

View File

@ -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 ();

View File

@ -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);