Help needed to fix the OgreAL threading issues


25-06-2008 18:04:57

I am still trying to fix OgreAL but I am struggling with the threading issues. CaseyB has not been around for ages, it makes thing difficult. I spent hours trying to understand what is going on but with no luck or really good progress.

Now, I think I know a bit more about the crash when sorting the active sound list.

std::sort(mActiveSounds.begin(), mActiveSounds.end(), SortLowToHigh());

The SortLowToHigh() function calls getDerivedPosition() on the node listener and sounds nodes as well.

Changing the position of the camera (used as the listener in openAL) or a sound node while sorting is a possible event considering that the nodes are updated in the Ogre thread. This would explain why the list or at least an iterator can easily become invalid when this happens.

Now my question is, how to lock the Ogre thread while sorting ? Do I need to compile a multithreaded version of Ogre and use some techniques like registerThread() and other OGRE_LOCK_MUTEX(mSceneMgr->sceneGraphMutex);

I read a few posts on the forum about the use of mutex or message queues...but nothing really clear enough. Maybe a simple example would be helpful. How to setup this message system and what kind of messages is required.

Any idea ? Any use of threads for physics, network, AI... must have similar issues I guess. Anyone here with threads programming experience ? OgreAL could be an excellent wrapper once the few remaining bugs are fixed up.

Thanks a lot