TGUI error: Failed to open widgets/Button/BabyBlue.
« on: 28 July 2013, 13:07:27 »
Hello. I was trying to compile this code:
Code: [Select]
#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.
« Last Edit: 28 July 2013, 13:09:50 by Jimmyee »

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: TGUI error: Failed to open widgets/Button/BabyBlue.
« Reply #1 on: 28 July 2013, 13:22:19 »
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:
Code: [Select]
button->load("widgets/BabyBlue.conf");

Re: TGUI error: Failed to open widgets/Button/BabyBlue.
« Reply #2 on: 28 July 2013, 13:26:59 »
Thank you for the answer! The problem seems to be solved but I still see just a black screen...

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: TGUI error: Failed to open widgets/Button/BabyBlue.
« Reply #3 on: 28 July 2013, 14:20:41 »
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.

Re: TGUI error: Failed to open widgets/Button/BabyBlue.
« Reply #4 on: 28 July 2013, 14:30:48 »
Quote
Are 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.
Code: [Select]
#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;
}

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

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

Quote
You 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
« Last Edit: 28 July 2013, 14:35:54 by Jimmyee »

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: TGUI error: Failed to open widgets/Button/BabyBlue.
« Reply #5 on: 28 July 2013, 14:40:22 »
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:
Quote
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.

Re: TGUI error: Failed to open widgets/Button/BabyBlue.
« Reply #6 on: 28 July 2013, 14:48:06 »
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.
« Last Edit: 28 July 2013, 15:05:18 by Jimmyee »

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: TGUI error: Failed to open widgets/Button/BabyBlue.
« Reply #7 on: 28 July 2013, 15:15:17 »
Quote
It 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.