Getting an error after drawing a widget
« on: 28 December 2018, 20:01:20 »
Hi all,
I'm new with the TGUI library and I don't really know how to fix this problem. I've tried to add a simple widget to my program (as it's showed in the tutorial):
Code: [Select]
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <TGUI/TGUI.hpp>

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

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

else if (event.type == sf::Event::Resized)
{
window.setView(sf::View(sf::FloatRect(0, 0, (float)event.size.width, (float)event.size.height)));
gui.setView(window.getView());
}

gui.handleEvent(event);
}

tgui::Button::Ptr button = tgui::Button::create("Login");
button->setSize("10%", "5%");
button->setPosition("30%", "10%");

gui.add(button);

window.clear();

gui.draw();

window.display();
}

return 0;
}


After debugging the whole code I got the following error in the console window:
"sfml-graphics requires support for OpenGL 1.1 or greater
Ensure that hardware acceleration is enabled if available"

Also, Visual Studio points out an unhandled exception at "gui.draw();" line.
Do you have any ideas how to fix this? (Sorry for my bad english)

*

texus

  • *****
  • 1334
    • View Profile
    • Texus's Blog
Re: Getting an error after drawing a widget
« Reply #1 on: 28 December 2018, 22:53:23 »
TGUI throws exceptions when things go wrong. Some compilers show the text when it happens, but Visual Studio doesn't. So if the "unhandled exception" is a TGUI exception then you have to catch it yourself. You basically need to put something like this around your code:
throw
{
    // Code goes here
}
catch (const tgui::Exception& e)
{
    std::cerr << "TGUI Exception: " << e.what() << std::endl;
    return 1;
}

I'm not aware of any TGUI exception that can be thrown during drawing though, so if the above still crashes on the same line then it isn't a TGUI exception being thrown. You can try changing "tgui::Exception" with "std::exception" and see if that shows a clearer error.

I've seen crashes before on the gui.draw call which were caused by incompatible libraries. So you may want to double check that both SFML and TGUI libraries are for your exact compiler version and you aren't mixing debug/release or dynamic/static libraries.

Quote
After debugging the whole code I got the following error in the console window:
"sfml-graphics requires support for OpenGL 1.1 or greater
Ensure that hardware acceleration is enabled if available"
Try installing the latest graphics driver for your video card just in case this has anything to do with it.

Re: Getting an error after drawing a widget
« Reply #2 on: 29 December 2018, 23:03:56 »
Thanks, finally all works. I had to add some .lib files to both Debug and Release folders.