TGUI Forum

General Category => Help requests => Topic started by: roccio on 08 June 2016, 17:27:56

Title: ListBox error
Post by: roccio on 08 June 2016, 17:27:56
Hello, I have a problem with the listbox.

What I have is this:
1 panel added to the main gui.
3 tabs added to the gui.
When I change tab i clear all widgets from the panel, and add the new ones.

All works fine, except if I try to add a listbox. The tab shows the correct listbox with the ites, but when I change tab the program crashes.

Any help?

Thank you for this very good library!

roccio
Title: Re: ListBox error
Post by: texus on 08 June 2016, 17:46:57
Could you show some code that I can test here? (ideally a simple main function that only creates the necessary objects to reproduce the issue)
Title: Re: ListBox error
Post by: roccio on 09 June 2016, 09:02:12
Here is the code

#include <TGUI/TGUI.hpp>

tgui::Gui g_gui;

void CreateTab1()
{
        tgui::Panel::Ptr panel = g_gui.get<tgui::Panel>("MAIN_PANEL");
        panel->removeAllWidgets();

        tgui::CheckBox::Ptr checkbox = std::make_shared<tgui::CheckBox>();
        checkbox->setPosition(10, 20);
        checkbox->setText("check 1");
        checkbox->setSize(25, 25);
        panel->add(checkbox);
}

void CreateTab2()
{
        tgui::Panel::Ptr panel = g_gui.get<tgui::Panel>("MAIN_PANEL");
        panel->removeAllWidgets();

        tgui::CheckBox::Ptr checkbox = std::make_shared<tgui::CheckBox>();
        checkbox->setPosition(10, 20);
        checkbox->setText("check 2");
        checkbox->setSize(25, 25);
        panel->add(checkbox);

        tgui::ListBox::Ptr listBox = std::make_shared<tgui::ListBox>();
        listBox->setSize(250, 120);
        listBox->setItemHeight(25);
        listBox->setPosition(10, 50);
        listBox->addItem("Item 1");
        listBox->addItem("Item 2");
        listBox->addItem("Item 3");
        panel->add(listBox);
}

void CreateTab3()
{
        tgui::Panel::Ptr panel = g_gui.get<tgui::Panel>("MAIN_PANEL");
        panel->removeAllWidgets();

        tgui::CheckBox::Ptr checkbox = std::make_shared<tgui::CheckBox>();
        checkbox->setPosition(10, 20);
        checkbox->setText("check 3");
        checkbox->setSize(25, 25);
        panel->add(checkbox);
}

void CreateTab4()
{
        tgui::Panel::Ptr panel = g_gui.get<tgui::Panel>("MAIN_PANEL");
        panel->removeAllWidgets();

        tgui::CheckBox::Ptr checkbox = std::make_shared<tgui::CheckBox>();
        checkbox->setPosition(10, 20);
        checkbox->setText("check 4");
        checkbox->setSize(25, 25);
        panel->add(checkbox);
}

void OnTabChange(std::string selectedTab)
{
        if (selectedTab == "TAB1")
                CreateTab1();
        else if (selectedTab == "TAB2")
                CreateTab2();
        else if (selectedTab == "TAB3")
                CreateTab3();
        else if (selectedTab == "TAB4")
                CreateTab4();
}

int main()
{
        sf::RenderWindow window(sf::VideoMode(1024, 768), VERSION);
        g_gui.setWindow(window);


        tgui::Tab::Ptr tabs = std::make_shared<tgui::Tab>();
        tabs->add("TAB1");
        tabs->add("TAB2");
        tabs->add("TAB3");
        tabs->add("TAB4");
        tabs->setPosition(0, 0);
        g_gui.add(tabs, "MAIN_TABS");

        tgui::Panel::Ptr panel = std::make_shared<tgui::Panel>();
        panel->setSize(1024, 743);
        panel->setPosition(tabs->getPosition().x, tabs->getPosition().y + tabs->getTabHeight());
        g_gui.add(panel, "MAIN_PANEL");

        tabs->connect("TabSelected", OnTabChange);
        tabs->select("TAB1");

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

                        g_gui.handleEvent(event);
                }

                window.clear(sf::Color::White);
                g_gui.draw();
                window.display();
        }
}
Title: Re: ListBox error
Post by: texus on 09 June 2016, 10:44:24
Wow, you just discovered an issue in my signal code. I'll see if I can fix it easily somehow.
Title: Re: ListBox error
Post by: texus on 09 June 2016, 10:57:31
Luckily it was easy to fix. But you will have to download the latest tgui version from github (https://github.com/texus/TGUI/archive/master.zip) and build it yourself to get the fix.
Title: Re: ListBox error
Post by: roccio on 09 June 2016, 11:12:29
Thank you very much!
Title: Re: ListBox error
Post by: roccio on 09 June 2016, 11:44:58
I have another question, I have downloaded cmake and set it up and running, but I have problems compiling in VS2015 for the x64 platform.

I get this error

sfml-graphics.lib(sfml-graphics-2.dll) : fatal error LNK1112
Title: Re: ListBox error
Post by: texus on 09 June 2016, 11:51:32
Based on the msdn (https://msdn.microsoft.com/en-us/library/21ksa10x.aspx) website that error means that you are mixing 32-bit and 64-bit.

Are you certain that the sfml dlls are 64-bit?
What generator did you select in CMake?
Title: Re: ListBox error
Post by: roccio on 09 June 2016, 11:54:22
The sfml libs are 64 bit, my generator is Visual Studio 14 2015
Title: Re: ListBox error
Post by: texus on 09 June 2016, 11:56:01
For 64-bit builds there is a "Visual Studio 14 2015 Win64" generator.
Using that one should fix the issue.
Title: Re: ListBox error
Post by: roccio on 09 June 2016, 12:24:23
Ok, compiled and tested the original problem. Now it works!

Thank you!