TGUI Forum

General Category => Help requests => Topic started by: cookie on 07 December 2015, 00:48:20

Title: Assertion Error when using VerticalLayout and bindWidth/bindHeight
Post by: cookie on 07 December 2015, 00:48:20
Hey there,
I'm using the precompiled TGUI v0.7-alpha2 for Visual C++14 (2015) 32 bit with SFML-2.3.2. I have linked it static.
Since I just had started using this awesome library, I copied the example code (https://tgui.eu/example-code/v0.7/scalable-login-screen/) for the scalable login screen and modified it to produce the error.
The scalable screen worked well when I directly attached the widgets to the gui like in the original example, but when I have started using the tgui::VerticalLayout things get a bit wired.
When I uncomment line 21 where I insert a space in between the two buttons in the layout, it will throw a assertion error when you scale the window on the y axis. Scaling on the x axis works perfectly. It also works perfect if there is no space in the layout or if I don't use a layout at all.

The error occours in line 56 when
Code: [Select]
gui.setView(window.getView()); is called.

The exact error:
Code: [Select]
Debug Assertion Failed!
File: [...]\Microsoft Visual Studio\14.0\VC\include\vector
Line: 101
Vector iterator not incrementable

The release mode will also throw an error, but a little bit different.

The code used to get this error:
(mostly the example)
Code: [Select]
#include <TGUI/TGUI.hpp>

void loadWidgets(tgui::Gui& gui)
{
// Create GUI
// Update size on window resize
auto windowWidth = tgui::bindWidth(gui);
auto windowHeight = tgui::bindHeight(gui);

// Vertical Layout
auto MenuLayout = std::make_shared<tgui::VerticalLayout>();
MenuLayout->setSize(windowWidth * 0.6f, windowHeight * 0.8f);
MenuLayout->setPosition(windowWidth * 0.2f, windowHeight * 0.1f);
gui.add(MenuLayout);

// Play Button
auto PlayBtn = std::make_shared<tgui::Button>();
//MenuLayout->add(PlayBtn);

/* ### Error line ### */
MenuLayout->addSpace(0.5f);

// Exit Button
auto ExitBtn = std::make_shared<tgui::Button>();
MenuLayout->add(ExitBtn);
}

int main()
{
// Create the window
sf::RenderWindow window(sf::VideoMode(400, 300), "TGUI window");
tgui::Gui gui(window);

try {
// Load the font
gui.setFont("Arial.ttf");

// Load the widgets
loadWidgets(gui);
} catch(const tgui::Exception& e) {
std::cerr << "Failed to load TGUI widgets: " << e.what() << std::endl;
return 1;
}

// Main loop
while(window.isOpen()) {
sf::Event event;
while(window.pollEvent(event)) {
// When the window is closed, the application ends
if(event.type == sf::Event::Closed)
window.close();

// When the window is resized, the view is changed
else if(event.type == sf::Event::Resized) {
window.setView(sf::View(sf::FloatRect(0, 0, event.size.width, event.size.height)));
gui.setView(window.getView());
}

// Pass the event to all the widgets
gui.handleEvent(event);
}

window.clear();

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

window.display();
}

return EXIT_SUCCESS;
}

Thanks for your help :)

cookie
Title: Re: Assertion Error when using VerticalLayout and bindWidth/bindHeight
Post by: texus on 07 December 2015, 08:34:14
It seems like this bug has already been fixed in the latest version, you can download it from github (https://github.com/texus/TGUI). You have to build it yourself with CMake.

You made me realize that the latest version on my download page is v0.7-alpha2. I will add a link to the source code of the latest snapshot as well, because there have already been quite some bug fixes.
Title: Worked!
Post by: cookie on 07 December 2015, 19:17:01
Thanks Texus!
The latest code from github worked for me!

cookie