ListBox error
« 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

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: ListBox error
« Reply #1 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)

Re: ListBox error
« Reply #2 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();
        }
}

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: ListBox error
« Reply #3 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.

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: ListBox error
« Reply #4 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 and build it yourself to get the fix.

Re: ListBox error
« Reply #5 on: 09 June 2016, 11:12:29 »
Thank you very much!

Re: ListBox error
« Reply #6 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
« Last Edit: 09 June 2016, 11:46:56 by roccio »

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: ListBox error
« Reply #7 on: 09 June 2016, 11:51:32 »
Based on the msdn 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?

Re: ListBox error
« Reply #8 on: 09 June 2016, 11:54:22 »
The sfml libs are 64 bit, my generator is Visual Studio 14 2015

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: ListBox error
« Reply #9 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.

Re: ListBox error
« Reply #10 on: 09 June 2016, 12:24:23 »
Ok, compiled and tested the original problem. Now it works!

Thank you!