Window Crashes beacouse cant load objects

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

senhor

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->load("Back1.png");
    picture->setSize(800, 600);

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

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

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

    // Create the password label
    tgui::Label* labelPassword = window.add<tgui::Label>();
    labelPassword->setText("Password:");
    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);
    editBoxPassword->setPasswordChar('*');

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

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

    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)
    window.globalFont.loadFromFile("D:/TGUI/Fonts/DejaVuSans.ttf");

    loadObjects( window );

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

            // Pass the event to all the objects (if there would be objects)
            window.handleEvent(event);
        }

        window.clear();

        // Draw all created objects
        window.drawGUI();

        window.display();
    }

    return EXIT_SUCCESS;
}



texus

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).

senhor

it crashes there:
editBoxUsername->load("objects/EditBox/Black");

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

texus

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

senhor


texus

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 https://tgui.eu/download/, do you see the v0.6 alpha2 versions with a line through them, or do you see the downloadable v0.6 beta?

senhor

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.

texus

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.

senhor

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

texus

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.

senhor

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

texus