MenuBar problem
« on: 10 May 2018, 14:35:36 »
Hello,
I have updated SFML to 2.5.0 and TGUI 0.8 dev all compiled with source by myself.
It all works well, but I have a problem when using tgui::Menubar.

What I do is just this:
- load a font
- set this font to tgui::gui
- create a MenuBar
- add menubar to gui

then normal event processing and rendering.

All works, only when I close the program I have this error:

Failed to activate OpenGL context: Operazione completata.

An internal OpenGL call failed in Texture.cpp(117).
Expression:
   glDeleteTextures(1, &texture)
Error description:
   GL_INVALID_OPERATION
   The specified operation is not allowed in the current state.


This is not happening if I just don't add the menubar to gui.

Is there something I miss?

*

texus

  • *****
  • 1232
    • View Profile
    • Texus's Blog
Re: MenuBar problem
« Reply #1 on: 10 May 2018, 14:42:01 »
Looks like something isn't being destroyed before the end of the main function. SFML textures (which are also used inside a font) can't exist in global scope. If a reference to the menu bar still exists at the end of the program then you could get issues like this.
If neither the font, gui or menu bar are static variables then you should try reducing the code to a simple example that still crashes.

Re: MenuBar problem
« Reply #2 on: 10 May 2018, 14:50:26 »
Here it is:

Code: [Select]
int main(int argc, char** argv)
{
sf::RenderWindow window;
sf::Font font;
tgui::Gui gui;

window.create(sf::VideoMode(800, 600), VERSION, sf::Style::Close);
window.setFramerateLimit(60);

font.loadFromFile("fonts\\segoeui.ttf");
gui.setTarget(window);
gui.setFont(font);

tgui::MenuBar::Ptr  menu = tgui::MenuBar::create();
gui.add(menu);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
return 0;

gui.handleEvent(event);
}
window.clear(sf::Color(223, 223, 223));
gui.draw();
window.display();
}

return 9;

Just comment the
gui.add(menu);

and no errors on exit

*

texus

  • *****
  • 1232
    • View Profile
    • Texus's Blog
Re: MenuBar problem
« Reply #3 on: 10 May 2018, 15:11:15 »
It might not be so easy to reproduce (it doesn't give any errors here and valgrind doesn't show anything useful). So I'm going to need to get a similar setup as yours:
What compiler are you using? Are you linking statically or dynamically? Release or debug mode?

Re: MenuBar problem
« Reply #4 on: 10 May 2018, 16:21:32 »
I'm using Visual C++ 2015 and using dynamic link.

Re: MenuBar problem
« Reply #5 on: 10 May 2018, 16:36:05 »
To not have the error you can comment the gui.add(menu) line OR gui.setFont(font);

 :-\

*

texus

  • *****
  • 1232
    • View Profile
    • Texus's Blog
Re: MenuBar problem
« Reply #6 on: 10 May 2018, 16:38:56 »
I managed to reproduce it (the code can even be simplified further, the sfml window and main loop can be removed and it still occurs), but I haven't figured out yet what could be causing it. But it is definitely a problem inside TGUI.

*

texus

  • *****
  • 1232
    • View Profile
    • Texus's Blog
Re: MenuBar problem
« Reply #7 on: 10 May 2018, 19:12:59 »
It should be fixed in the latest version now: https://github.com/texus/TGUI/archive/0.8-dev.zip

Re: MenuBar problem
« Reply #8 on: 11 May 2018, 09:12:17 »
Seems to work well now.
Thank you, great work!