TGUI error: Failed to open widgets/Button/BabyBlue.

Started by Jimmyee, 28 July 2013, 13:07:27

Jimmyee

Hello. I was trying to compile this code:

#include <TGUI/TGUI.hpp>

int main()
{
    // Create the window
    sf::RenderWindow window(sf::VideoMode(800, 600), "Window");
    tgui::Gui gui(window);

    // Load the font (you should check the return value to make sure that it is loaded)
    gui.setGlobalFont("fonts/DejaVuSans.ttf");

    tgui::Button::Ptr button(gui, "btnTileset");
    button->load("widgets/Button/BabyBlue");
    button->setText("Tileset");
    button->setSize(80, 20);
    button->setPosition(4, 4);

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

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

        window.clear();

        // Draw all created widgets
        gui.draw();

        window.display();
    }

    return EXIT_SUCCESS;
}


The "widgets" and "fonts" folders are in the same folder as the app is. What might be the problem?
This is TGUI v0.6 of course.

texus

A lot has changed since v0.5, including the way widgets are loaded.
They are now loaded with a config file instead of through a path name.

So to load the button you would need:
button->load("widgets/BabyBlue.conf");

Jimmyee

Thank you for the answer! The problem seems to be solved but I still see just a black screen...

texus

Strange, it works for me.

Are you still using the exact same code as above with only the button->load line changed?
What does the load function return, true of false?
Did you copy the widgets folder from tgui as-is, without changing any files?
Nothing is being printed in the terminal?

You could also try loading Black.conf instead and see if it gives the same result.

Jimmyee

QuoteAre you still using the exact same code as above with only the button->load line changed?
I will paste the code I'm using now.

#include <TGUI/TGUI.hpp>

int main()
{
    // Create the window
    sf::RenderWindow window(sf::VideoMode(800, 600), "Window");
    tgui::Gui gui(window);

    // Load the font (you should check the return value to make sure that it is loaded)
    gui.setGlobalFont("gfx/fonts/DejaVuSans.ttf");

    tgui::Button::Ptr button(gui, "btnTileset");
    if(!button->load("gfx/gui/widgets/BabyBlue.conf"))
    {
        puts("Could not load button graphics!");
    }
    button->setText("Tileset");
    button->setSize(100, 50);
    button->setPosition(50, 50);

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

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

        tgui::Callback callback;
        while (gui.pollCallback(callback))
        {
        }

        window.clear();

        // Draw all created widgets
        gui.draw();

        window.display();
    }

    return EXIT_SUCCESS;
}


QuoteWhat does the load function return, true of false?
It returns true for me (it doesn't display the error message).

QuoteDid you copy the widgets folder from tgui as-is, without changing any files?
Yep... I didn't change anything there.

QuoteYou could also try loading Black.conf instead and see if it gives the same result.
I'll try but first I wanna show you something.
There is an app crash when I close the window. After debugging I get this:


EDIT: using Black.conf it works the same way like with BabyBlue.conf

texus

Are you by any chance using c++11?

I recently was made aware that if you use the "-std=c++11" option for your own project, you should also compile tgui with this option.
I added a warning for that in the tutorial:
QuoteIf you are going to use c++11 then you will have to check "Advanced" and add "-std=c++11″ (or "-std=c++0x" if you have an older compiler) to CMAKE_CXX_FLAGS.
That is what you have to do in cmake to compile tgui with c++11.

The crash at exit is caused by this, and perhaps your other problem as well.

Jimmyee

Quote from: texus on 28 July 2013, 14:40:22
Are you by any chance using c++11?

Yeah I do... And I didn't read the whole tutorial. Thank you for the information. Next time I'll read everything.

EDIT: It works now.

texus

QuoteIt works now.
Although this is good to hear, it means that the c++11 issue is more severe than I thought.
Getting strange behaviour just because the library wasn't compiled correctly isn't very good.

I tried to delay it as long as possible, but it is time that tgui starts making use of c++11.
I'll replace boost with c++11 ASAP to get rid of these problems. Then I can also finally start making use of the many c++11 features that I couldn't use until now.