Segmentation fault when a list of tgui::Group::Ptr gets destroyed

Started by GetterSetter, 25 March 2024, 16:17:13

GetterSetter

Hello, I suppose that I'm missing something but can't figure out what. I have the next class (some realization nuances are omitted):
class Scene
{
public:
    std::list<tgui::Group::Ptr> groups;
private:
    using iterator = std::list<tgui::Group::Ptr>::iterator;
    iterator current_group;
    void change_scene(iterator &from, iterator &to);

};

In the main function I have something like that:

scene.groups.emplace_back(tgui::Group::create());

//Some widgets initialization and adding them to the group

gui.add(scene.groups.begin());
It works pretty nice until I close the program (and ~Scene() is called) and get Seg fault message. I've attached the picture from the debugger.

texus

Is the Scene class perhaps being destructed after the main() function has finished executing?
SFML and TGUI objects need to be destroyed before the end of the main function and shouldn't be part of a static global object.

Edit: Also, all TGUI widgets need to be destroyed before the Gui object is destroyed.

GetterSetter

Quote from: texus on 25 March 2024, 18:24:54all TGUI widgets need to be destroyed before the Gui object is destroyed.
Oh, that's it. I swapped two lines in the code (see below) and it settled the matter, thank you!
//How it was:
Scene scene;
tgui::Gui gui;

//How it is now:
tgui::Gui gui;
Scene scene;