Adding widget to group crashes

  • 22 Replies
  • 176 Views
Adding widget to group crashes
« on: 16 May 2020, 15:35:46 »
Hello,

I have a very simple problem but I couldn't find the solution by myself or on this forum...

Adding any widget to my group makes my application crash.

I have a classe named Application, it has a tgui object called tgui.
When I create Application, I try to do this :
Application::Application()
{
    // Some code

    // Graphical User Interface
    Application::tgui.setTarget(Application::window); // setting my tgui object on my window object
    try
    {
        auto button1 = tgui::Button::create();
        auto group = tgui::Group::create();

        group->add(button1, "button"); // CRASH

    }
    catch (const tgui::Exception& e)
    {
        std::cerr << "TGUI Exception: " << e.what() << std::endl;
    }
}
 

I don't have any answer from cerr, and I don't understand why this would crash ?

Thank you for your help !

*

texus

  • *****
  • 1539
    • View Profile
    • Texus's Blog
Re: Adding widget to group crashes
« Reply #1 on: 16 May 2020, 16:05:53 »
You should check the call stack from the debugger to see if it gives any more information.
Are window and tgui static member variables? They should be initialized by the class constructor and not at program startup before the main function gets executed (which happens with globals or static members), as that could give issues.

Re: Adding widget to group crashes
« Reply #2 on: 16 May 2020, 17:07:30 »
Thanks for your answer !

My tgui object is member of my class Application :
class Application
{
    public:
        Application();

        sf::RenderWindow window;

        tgui::Gui tgui; // GUI

    protected:

    private:

};

So it's created in my main when I create an instance of Application :
int main()
{
    Application app;

    Mainmenu(&app);

    return 0;
}
 

Is that bad ? If I initialize it in the constructor then it will be deleted after I call it ?

*

texus

  • *****
  • 1539
    • View Profile
    • Texus's Blog
Re: Adding widget to group crashes
« Reply #3 on: 16 May 2020, 17:18:05 »
Your method is correct, the window and gui will be constructed when the "app" object is created and destructed at the end of the main function.
The reason why I though you might be using static variables is because it is weird that you typed "Application::" in front of "tgui" and "window" in your original code. People don't usually add the class name before their member names unless it is a static variable or when calling a function from a base class that is overridden in the derived class. You would normally just type "tgui", or "this->tgui" if people really want to show that it is a member variable. So the syntax was a bit unusual, but there is nothing wrong with the code you showed.

You should have a look at the call stack then as I wouldn't know what else could cause it.

Re: Adding widget to group crashes
« Reply #4 on: 16 May 2020, 17:30:19 »
My debugger tells me it's a SIGSEGV (Segmentation Fault), when the app come to :  group->add(button1, "button");

I have absolutely no idea of what this means :/

*

texus

  • *****
  • 1539
    • View Profile
    • Texus's Blog
Re: Adding widget to group crashes
« Reply #5 on: 16 May 2020, 17:36:35 »
What IDE are you using? Visual Studio?

Re: Adding widget to group crashes
« Reply #6 on: 16 May 2020, 17:41:31 »
Codeblocks 17.12

*

texus

  • *****
  • 1539
    • View Profile
    • Texus's Blog
Re: Adding widget to group crashes
« Reply #7 on: 16 May 2020, 18:09:18 »
In the menu bar, check Debug > Debugging Windows > Call Stack.
When it crashes, it shows which functions gets called where. If you are in debug mode and linking to the TGUI libraries ending with "-d" then it will even show where inside the TGUI library it crashes.
If you can send the entire call stack then I may be able to see what went wrong.

Re: Adding widget to group crashes
« Reply #8 on: 16 May 2020, 18:58:15 »
I think I linked everything but I only have this in call stack :

#0 ??   ?? () (??:??)
#1 0x410c60     Application::Application(this=0x14268d0) (D:\Documents\Programmation\X22 Colonization\X22_Data.cpp:48)
#2 0x401437     main() (D:\Documents\Programmation\X22 Colonization\main.cpp:36)
 

and logs :
Debugger name and version: GNU gdb (GDB) 7.9.1
Child process PID: 17848
Program received signal SIGSEGV, Segmentation fault.
In ?? () ()
#1  0x00410c60 in Application::Application (this=0x14268d0) at D:\Documents\Programmation\X22 Colonization\X22_Data.cpp:48
D:\Documents\Programmation\X22 Colonization\X22_Data.cpp:48:1667:beg:0x410c60
At D:\Documents\Programmation\X22 Colonization\X22_Data.cpp:48
#1  0x00410c60 in Application::Application (this=0x14268d0) at D:\Documents\Programmation\X22 Colonization\X22_Data.cpp:48
D:\Documents\Programmation\X22 Colonization\X22_Data.cpp:48:1667:beg:0x410c60
Debugger finished with status 0
 

I must have done a mistake somewhere when installing or something ? But  everything's works fine except this damn line, so I don't understand. Thanks for your help anyway, I keep on looking for the problem...

*

texus

  • *****
  • 1539
    • View Profile
    • Texus's Blog
Re: Adding widget to group crashes
« Reply #9 on: 16 May 2020, 18:59:05 »
Are you in debug or release mode? Which libraries are you linking exactly?

Re: Adding widget to group crashes
« Reply #10 on: 16 May 2020, 19:23:45 »
Yes I'm in debug mode, and here is a picture of my linker settings.


*

texus

  • *****
  • 1539
    • View Profile
    • Texus's Blog
Re: Adding widget to group crashes
« Reply #11 on: 16 May 2020, 19:26:39 »
Could you send the full source code that you are using so that I can try to run it here and see if it crashes here as well?

Re: Adding widget to group crashes
« Reply #12 on: 16 May 2020, 20:03:28 »
It would be difficult for me to send all sources, but I tried to duplicate the problem based on your login screen example (https://tgui.eu/examples/0.8/scalable-login-screen/) and I have the same problem, just by modifying this function :

void loadWidgets( tgui::Gui& gui )
{
    auto button1 = tgui::Button::create();
    auto group = tgui::Group::create();

    group->add(button1, "button");

    gui.add(group);
}
 

Segmentation fault :/

*

texus

  • *****
  • 1539
    • View Profile
    • Texus's Blog
Re: Adding widget to group crashes
« Reply #13 on: 16 May 2020, 22:10:50 »
Then the only thing I can think of is if the libraries aren't compatible.
Are you using the SFML and TGUI libraries that you downloaded from sfml and tgui websites? Are you using the GCC compiler that comes with codeblocks 17.12? Did you download the SFML and TGUI libraries for exactly this compiler (MinGW 5.1.0 TDM for the one that can be installed together with CodeBlocks)?
Could you send me the .cbp file from your project?

Re: Adding widget to group crashes
« Reply #14 on: 20 May 2020, 17:25:05 »
Hello,

Here it is. Hope you can find something and thank you again for the support :)