Page 1 of 1

Multiple Render Windows in Qt application

Posted: Thu Feb 01, 2018 6:20 pm
by MMI
I'm currently trying to debug a problem with an Ogre 1.10 app using Qt5 and several render widgets. Everything works fine until I'm deleting certain widgets, any subsequent call to create a Renderable on other windows fail on some systems (Apple, Windows and Ubuntu with certain drivers confirmed, other systems run fine).

In short, I get an exception e.g. here:

https://github.com/OGRECave/ogre/blob/0 ... er.cpp#L46

Debugging the problem, I can see that "mBufferId" is really 0, which as far as I can tell will only really happen when the OpenGL context is somehow gone. Apart from whatever Qt does, the code under my control is single-threaded.

- To confirm my suspicion, is there a possibility to ask Ogre whether it currently has a context? I could in principle modify Ogre's code, but I can't get a call such as wglGetCurrentContext() to link properly.
- If the context is really lost, I guess there are some errors in the interplay between Ogre and Qt. Does there exist documentation/best practices on how to make a Qt-Ogre app with widgets and several render windows which can be opened and closed ad libitum? I found some bits of information here and there, but most of it outdated.

Re: Multiple Render Windows in Qt application

Posted: Thu Feb 01, 2018 7:26 pm
by paroj
ogre has the notion of a "main" context. It is used to share OpenGL resources between contexts. See:
https://github.com/OGRECave/ogre/blob/m ... xt.cpp#L43

while using multiple contexts does work, it is much easier just to use the same context for all your windows. This is what Bites does:
https://github.com/OGRECave/ogre/blob/m ... t.cpp#L350

However in both cases you must pay attention not to delete your main context ("destroy" the main window).
Probably this is what is causing the issues for you.

Re: Multiple Render Windows in Qt application

Posted: Mon Feb 05, 2018 2:39 pm
by MMI
Thank you very much, that helped clear up some things.

With that, I could find the problem. The code didn't destroy the second Ogre::RenderWindow properly, it just called "delete" to the pointer. When calling destroy() first, everything works as expected.