ListBox error

Started by roccio, 08 June 2016, 17:27:56

roccio

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

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)

roccio

Here is the code

Code (cpp) Select

#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

Wow, you just discovered an issue in my signal code. I'll see if I can fix it easily somehow.

texus

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.

roccio

Thank you very much!

roccio

#6
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

texus

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?

roccio

The sfml libs are 64 bit, my generator is Visual Studio 14 2015

texus

For 64-bit builds there is a "Visual Studio 14 2015 Win64" generator.
Using that one should fix the issue.

roccio

Ok, compiled and tested the original problem. Now it works!

Thank you!