Window Crashes beacouse cant load objects

Started by senhor, 16 October 2013, 02:15:00


I am trying to run that code but it crashes when it try to load an object:

#include <TGUI/TGUI.hpp>
#include <iostream>

void loadObjects( tgui::Window& window )
    // Create the background image
    tgui::Picture* picture = window.add<tgui::Picture>();
    picture->setSize(800, 600);

    std::cout << "1\n";

    // Create the username label
    tgui::Label* labelUsername = window.add<tgui::Label>();
    labelUsername->setPosition(200, 100);

    std::cout << "2\n";

    // Create the password label
    tgui::Label* labelPassword = window.add<tgui::Label>();
    labelPassword->setPosition(200, 250);

    std::cout << "3\n";

    // Create the username edit box
    tgui::EditBox* editBoxUsername = window.add<tgui::EditBox>();     std::cout << "3.2\n";
    editBoxUsername->load("objects/EditBox/Black");                   std::cout << "3.4\n";
    editBoxUsername->setSize(400, 40);                                std::cout << "3.6\n";
    editBoxUsername->setPosition(200, 140);                           std::cout << "3.8\n";

    std::cout << "4\n";

    // Create the password edit box (we will copy the previously created edit box)
    tgui::EditBox* editBoxPassword = window.copy(editBoxUsername);
    editBoxPassword->setPosition(200, 290);

    std::cout << "5\n";

    // Create the login button
    tgui::Button* button = window.add<tgui::Button>();
    button->setSize(260, 60);
    button->setPosition(270, 440);

    std::cout << "6";

int main()
    // Create the window
    tgui::Window window(sf::VideoMode(800, 600), "TGUI window");

    // Load the font (you should check the return value to make sure that it is loaded)

    loadObjects( window );

    while (window.isOpen())
        sf::Event event;
        while (window.pollEvent(event))
            if (event.type == sf::Event::Closed)

            // Pass the event to all the objects (if there would be objects)


        // Draw all created objects


    return EXIT_SUCCESS;


With what compiler?
Where does it crash (use the debugger to get the location and call stack)?
Are you linking to the static or dynamic libraries?
Does it occur in debug or release mode?

I can't help without enough information. I either need to reproduce the issue (which I probably won't with such simple code) or get enough information in the hope that I can tell you what the problem is.

If you are on windows then you should first of all make sure that when you link tgui statically then you also link sfml statically (or link both dynamically), and make sure that when in release mode you link both sfml and tgui in release mode (and in debug mode link the debug libs of both).


it crashes there:

I am using TDM 4.8 with code blocks 12.11

I am using them staticly

My debugger dont run and I dont know why

it crashes in debug mod


Could you send me the .cbp file?
Maybe I can find the mistake that way.



The program works fine for me. I just removed the sfml dependencies (freetype and stuff) from the linker as they aren't needed, they are linked inside the sfml libraries.
But with the compiler that comes with code blocks and the libraries downloaded from my site everything seems to work.

Wait, did you say gcc 4.8?
Did you recompile tgui? Because the precompiled version is for gcc 4.7.

I have an unrelated question. When you visit, do you see the v0.6 alpha2 versions with a line through them, or do you see the downloadable v0.6 beta?


I couldnt recompile it because it says cmake cant find sfml even when I choose my sfml directory.
SFML dont work on my computer without including that stuff which you removed.
I see that:

Precompiled libraries were removed after a big memory leak was found (September 13th). The problem has been fixed in the latest development snapshot.
Download TGUI v0.6 alpha2 (with precompiled GCC 4.7 TDM (SJLJ) 32 bits libraries for SFML 2.1)
Download TGUI v0.6 alpha2 (with precompiled Visual C++ 10 (2010) 32 bits libraries for SFML 2.1)
Download TGUI v0.6 alpha2 (with precompiled Visual C++ 11 (2012) 32 bits libraries for SFML 2.1)

Download the latest development snapshot from github.


Something is seriously wrong, I just don't know what.
The crash could be explained if you use gcc 4.8 though. Libraries aren't compatible between different compiler versions.
But that means that you had to recompile sfml yourself, right? Because the precompiled binary of sfml is also gcc 4.7. And if you compiled it yourself then it would expain the error that cmake can't find sfml because you have to copy the lib folder from the build folder to the root folder.

QuoteI see that:
That explains why people still download v0.5 while the v0.6-beta was released over 2 weeks ago. Damn caching. Fixed.


I didnt understand what did you say but I have already compiled sfml myself. Does tgui need static or dynamic libs on SFML folder?


If you compile sfml yourself then you will get a 'build' folder which contains a lib folder with the compiled libraries.
This lib folder has to be copied to the root folder of sfml (next to the include folder).

When compiling tgui, you need to set SFML_ROOT to this root folder, which has to contain these 'include' and 'lib' folders, as the cmake error says.

QuoteDoes tgui need static or dynamic libs on SFML folder?
When building statically you need the static libs and when building dynamic you need the dynamic libs.
You can't mix those.


I have already done what you say.

Btw have you got a skype account so we can talk there, btw we have a c++ group on skype