Adding widget to group crashes

Started by r4gTime, 16 May 2020, 15:35:46

r4gTime

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 :
Code (cpp) Select
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

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.

r4gTime

Thanks for your answer !

My tgui object is member of my class Application :
Code (cpp) Select
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 :
Code (cpp) Select

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

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.

r4gTime

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

What IDE are you using? Visual Studio?

r4gTime


texus

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.

r4gTime

I think I linked everything but I only have this in call stack :

Code (none) Select
#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 :
Code (none) Select
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

Are you in debug or release mode? Which libraries are you linking exactly?

r4gTime

Yes I'm in debug mode, and here is a picture of my linker settings.


texus

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?

r4gTime

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 :

Code (cpp) Select

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

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?

r4gTime

Hello,

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


texus

Everything seems to be configured correctly in the cbp file.

Could you send me your libsfml-graphics.a and libtgui.a files?


texus

I'm starting to run out of ideas on what the issue could be.
- Could you send me your TGUI/include/TGUI/Config.hpp file?
- In CodeBlocks in the menu under Settings > Compiler... in the "Toolchain executables" tab (in the tabs near the top of the Compiler settings window), what is the "Compiler's installation directory" set to?
- If you open a command prompt, what is the output of executing "echo %PATH%"?

r4gTime

Hello,

Here is the config and the compiler settings in attachments.

When I type echo %PATH% I get this :

C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\NVIDIA Corporation\NVIDIA NGX;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Users\Louis\AppData\Local\Microsoft\WindowsApps;

texus

I don't know what it could still be. The code works fine for others but everything seems to be set up correctly on your pc.

The only thing that wasn't normal in the things you send (except for the fact that you are receiving a segmentation fault) was the result of the call stack. Could you double check that you are running in Debug mode when you get that call stack? It shouldn't contain question marks on the top.

The only other thing you could still try is rebuilding TGUI yourself with cmake, but I fear that it isn't going to make a difference.

r4gTime

Yep I checked again...

F*** I didn't think 1 sec there could be no solution... Your GUI seems perfect for what  I need.

Thank again for your help and if I find something I'll let you know.

texus

Are you certain that the .dll files next to your exe are from the same place as the .a files? I didn't realize that possibility until I was creating a test here.

There is actually one more thing that we could test. I've created a project using the same compiler as yours. Could you try downloading it:
https://www.dropbox.com/s/iowa9pof9kx85td/TGUI-Test.7z?dl=0
(I've used 7z instead of a normal zip because it gave a big difference in size, download button should be at top right of page)

Try to run the TGUI-Test.exe inside the bin folder (either Debug or Release). If it complains about missing gcc and dlls then copy them from your "C:\Program Files (x86)\CodeBlocks\MinGW\bin" folder and put them next to the exe.
If the exe runs then try to open the .cbp project and building the project. Check if it still runs after you build the project.

r4gTime

Oh my god I tested the exact same thing you did 10mn ago and... it worked  ;D ;D

I used some dll files from 8.4 or 8.5 version and I didn't realize.

Thank you so much, I'm now ready to create a nice GUI for my game :)