Problems deleting Ogre::Root when using threads

Problems building or running the engine, queries about how to use features etc.
Post Reply
diegomp1982
Kobold
Posts: 38
Joined: Thu Jun 14, 2007 9:27 am
x 2

Problems deleting Ogre::Root when using threads

Post by diegomp1982 »

I'm using ogre with pthread for the thread management and there seem to be any problem.

The main application creates a thread which I use to handle everything that has to do with Ogre (initialization, loading resources, scene creation, rendering and disposal). Everything works ok, but when I call 'delete Root' to destroy Ogre (also inside the same thread) a segmentation fault rises.
I've tried the code using no threads (but the main one) and this problem does not appear. Also, I've tested the threads without adding any Ogre code and they work fine. In fact, everything works fine if I don't call 'delete Root'.

Any ideas?

Thanks in advance
Varela
Halfling
Posts: 45
Joined: Wed Apr 27, 2005 1:10 pm
Location: Portugal

Post by Varela »

I think deleting the root means shutting down Ogre because everything is attached to the root. There is the method root->shutdown the probably may solve your problem.
diegomp1982
Kobold
Posts: 38
Joined: Thu Jun 14, 2007 9:27 am
x 2

Post by diegomp1982 »

First of all, thank you very much for replying so fast, Varela, it's wonderfull finding a community where people takes so much interest in helping each other.
But, unluckily, shutting down Ogre does not release all the resources, neither closes the Graphic system.

I've looking to the Ogre::~Root and shutting down the system is the first thing it does, but it also deletes a lot of other member pointers. I was thinking of deleting them myself, but they are declared as private, and I don't want to change Ogre code in order to have my program working with new releases of Ogre.

Any more ideas??

PD->I've also looked at the API and I haven't found anything
User avatar
Numsgil
Gremlin
Posts: 197
Joined: Sun Jan 29, 2006 10:20 pm

Post by Numsgil »

I *think* you need to initialize and destroy Ogre in the app's primary thread.
Darwinbots, leading amateur artificial life simulator.
User avatar
bibiteinfo
Gremlin
Posts: 197
Joined: Wed Apr 12, 2006 2:48 pm
Location: Montreal, Canada

Post by bibiteinfo »

Numsgil wrote:I *think* you need to initialize and destroy Ogre in the app's primary thread.
This is right
Image
diegomp1982
Kobold
Posts: 38
Joined: Thu Jun 14, 2007 9:27 am
x 2

Post by diegomp1982 »

Thank you very much! I'll try it the sooner I can
diegomp1982
Kobold
Posts: 38
Joined: Thu Jun 14, 2007 9:27 am
x 2

Post by diegomp1982 »

I think this does not work either... Whenever I try to delegte mRoot from the main thread I get a segmentation fault message (and the program crashes!)
I think the only solution is using Ogre in the main thread but for design issues I am not willing to do so. The only solution I´ve reached is to call mRoot->shutDown(), but this does not unload the resources.
Anyway, the program shows no problems when rebooting.
User avatar
Bontakun
Goblin
Posts: 290
Joined: Tue Dec 09, 2003 6:09 am
Location: Melbourne, Australia

Post by Bontakun »

bibiteinfo wrote:
Numsgil wrote:I *think* you need to initialize and destroy Ogre in the app's primary thread.
This is right
Where are we told to do this?
- Bonta (eveonline:Dentad)
User avatar
bibiteinfo
Gremlin
Posts: 197
Joined: Wed Apr 12, 2006 2:48 pm
Location: Montreal, Canada

Post by bibiteinfo »

From this thread :

http://www.ogre3d.org/phpBB2/viewtopic. ... stroy+main

and the documentation

http://www.ogre3d.org/docs/api/html/cla ... ystem.html

Call this from your main thread before starting your other threads (which themselves should call registerThread()). Note that if you start your own threads, there is a specific startup sequence which must be respected and requires synchronisation between the threads:
Well it talks for startup sequence, but ending sequence is probably the same.
Image
User avatar
Bontakun
Goblin
Posts: 290
Joined: Tue Dec 09, 2003 6:09 am
Location: Melbourne, Australia

Post by Bontakun »

No actually those two references talk about when you have multiple threads calling the rendering system. I have multiple threads in my app but only one thread which is not the primary thread which calls Ogre and the rendering system.
- Bonta (eveonline:Dentad)
Post Reply