Project

General

Profile

adding Widget to root() ends in Segfault...

Added by Christian Meyer 2 months ago

Hi there.

I am at the end of my understanding.
I have two different WApplication , that are on the same Server.

The Constructor looks identical...

but adding the first Widget goes horribly wrong in One Application and just works fine in the other.

What makes it even harder to understand: The Segfault happens in App 1 regardless of the function used to add the WContainerWidget: addNew<WContainerWidget>() , addWidget(std::make_unique<WContainerWidget>()) , insertWidget(0, std::make_unique<WContainerWidget>())

in App2 it works...

I am pretty sure there is nothing wrong with Wt as this just happend recently and the second app within the same executable just works.

But if you have any slightest hint of an idea that might give me a pointer in the direction of solving this...
Please save my sanity

Adding Screenshots from the Debuging Steps of addWidget
Maybe that helps a little

Cheers
Christian

wt 4.10.0


Replies (5)

RE: adding Widget to root() ends in Segfault... - Added by Mark Petryk 2 months ago

Hi Christian

Would the following work;

template <typename Widget>
  Widget * addWidget( std::unique_ptr< Widget > widget )
  {
    Widget * result = widget.get();
    addWidget( std::move( widget ) );
    return result;
  }

RE: adding Widget to root() ends in Segfault... - Added by Christian Meyer 2 months ago

Hi Mark, thanks for looking into this.

Updating the Code in WContainerWidget.h to your suggestion throws something completely different in <tuple> in both Apps this time.

Stepping deeper into the Code, it seems there is something else:

WWebWidget *WWebWidget::parentWebWidget() const
{
  /*
   * Returns the parent webwidget, i.e. skipping composite widgets
   */
  WWidget *p = this->parent();
  while (p != nullptr && dynamic_cast<WCompositeWidget *>(p) != nullptr) // Throws here when adding to root() or setStyleClass() on root()
    p = p->parent();

  return p ? p->webWidget() : nullptr;
}

I'm still trying to locate the big differences between the working and the broken app...
the while loop goes through 2 steps before segfault

Updated to Wt 4.10.3, but still throws.

RE: adding Widget to root() ends in Segfault... - Added by Mark Petryk 2 months ago

Can you post code for an actual (small) working project that can demonstrate the error?

RE: adding Widget to root() ends in Segfault... - Added by Matthias Van Ceulebroeck 2 months ago

Hello Christian,

if it would indeed not be too much trouble, a minimal example would be nice.
From a glace, seeing that the widget is already a nullptr when addWidget is called, are you certain that the widget is constructed correctly, and not destructed earlier than expected? Again, that's just from a glance.

Best,
Matthias

[SOLVED]: adding Widget to root() ends in Segfault... - Added by Christian Meyer 2 months ago

Thanks for looking into this.

As Expected, there is nothing wrong with Wt...

To be honest, I really don't understand how this happened.
My guess is something to do with how I handled the ConnectionPool Object for each application and the Dbo::Session Object.

I need to look further into when to use unique_ptr and when not to!

At least, now it works in both Apps, and the previous error on Session exit that let me try different things seems to also have vanished.

Thank you for your time!

Good luck in your developments!

    (1-5/5)