Segfault with TGUI::Picture

Started by Dnake, 12 May 2015, 21:07:48

Dnake

Hi,
When I run the following code, I get a segfault at the end of the program, I guess when the tgui::Gui instance is destroyed.

#include <TGUI/TGUI.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "TGUI window");
    tgui::Gui gui(window);
    tgui::Picture::Ptr pic = tgui::Picture::create("Black.png");
    pic->setPosition(bindWidth(pic), 0.f);
    gui.add(pic);
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
            gui.handleEvent(event);
        }
        window.clear(sf::Color::White);
        gui.draw();
        window.display();
    }
    return 0;
}


The debugger tells me that the segfault comes from the line 110 in SFML's Texture.cpp (that's the only relevant information that the call stack gives), at this line:
110        glCheck(glDeleteTextures(1, &texture));

The code above is the minimal one that can reproduces the segfault, the image doesn't matter.
It seems to be related to the bindWidth(pic), when I give an expression independant from pic as layout for setPosition(), the segfault dissapears.

Note: I have to run the project two times to get the segfault, the first time everything works fine.

I run on Windows 7, with TGUI 0.7 and last SFML sources, with Mingw GCC 4.8.

Thanks :)

texus

I don't see how the layout system could be related to a crash about a texture, these parts of the code are completely separated. So it the problem really lies here then it is going to be hard to find. I also can't reproduce this on linux and my mingw compiler seems to be broken again.

First of all, you are not mixing debug/release or static/dynamic with each other, right? The sfml and tgui libraries have to be compiled with the same settings or very strange crashes can occur.

Quotethat's the only relevant information that the call stack gives
Call stacks on destructors indeed usually provide no relevant information, but if even one of these lines is about a tgui function then it might help. Are you linking in debug mode?

There is unfortunately not much that I can do to help right now. I'm going to try with visual studio now in the hope that it crashes there too. But if I can't find the problem in less than an hour you will have to wait until Thursday. Then I will also have the time to fix my mingw compiler.

texus

Bad news, it even works in visual studio, which is usually more likely to give errors and crashes than mingw.

So you should double check that the TGUI and SFML libraries are compatible. Both should be linked in release or both in debug. Both should be static, or both should be dynamic. I assume you also compiled sfml yourself, so I guess there won't be a problem with one of the libraries being compiled for a different compiler.

Dnake

Yes, I compiled both librairies in dynamic, in both debug and release, but when I compile the program in Debug, it asks for debug DLLs, so I assume that doesn't lies to that. The segfault is not very friendly, I cannot get it again when I run my program with gdb, but when I run the program normally I get it.

By the way, how can I help you to improve TGUI? I have got some free time these times, so maybe I can fix things or do work you don't have time to, and push it on you Github. I really like TGUI, and I would be glad to contribute to it!

texus

Quoteit asks for debug DLLs
Then just copy the dlls (which can be found in the lib folder inside the build folder that you created for cmake) next to the executable you are running (like you should have done for the release dlls already). You really need to run in debug mode to get most information.

QuoteI cannot get it again when I run my program with gdb, but when I run the program normally I get it.
Are you running it from the command prompt in both cases and in the same folder?

QuoteBy the way, how can I help you to improve TGUI?
For short term stuff I created a page on Trello. You could have a look at the tasks in the "Minor changes" section.

Dnake

I know that I have to copy DLLs, I said that to indicate that the program uses corrects DLLs. And yes I run it from command prompt in both cases. I'll take a look at the Trello page, thanks :)

texus

Which compiler are you using exactly (you already said mingw 4.8, but there are 3 different mingw versions)? Could you send a link to the page where you downloaded it?

Also could you upload the TGUI and SFML libraries that you build somewhere?

Then I can test this problem under the exact same circumstances.

texus

I can't reproduce it with the MinGW on my pc either. It really must be a combination of the libraries you have and the compiler.