Kodachi_Garou
31-01-2008 11:58:14
For months I've been dealing with strange phenomena like access violations or creation functions and properties returning null references, creeping in from Mogre library and have not been able to pin them down to a simple bullet-proof example until now. Some related previous post references: http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=5710 and http://www.ogre3d.org/phpBB2addons/view ... 7fc386b91b.
Ok, finally I've got it and it's bad, way BAD. There is indeed a bizarre bug with either Ogre or Mogre, but given the larger number of strange uses done with Ogre, for now I think it's the latter. I've found a simple bullet-proof condition for producing null reference pointers on Mogre function creation.
Just smack these two functions on your favorite Mogre sample and watch them blow:
What could this mean? Here's my two cents:
Basically, if you have a Thread which is concurrent with the Mogre thread and is somewhat allocating memory, or worse, freeing memory, Mogre will snap. Keep in mind that it is likely that this will only happen on dual-core machines, but I haven't tested this claim thouroughly.
This could come from a variety of sources, including input handling buffers like keyboard, mouse, video camera threads, etc.
If there is a high memory manipulation from both the Mogre thread and the memory handling thread, Mogre will crash hard, even if the thread is completely independent with nothing to do with Mogre data structures.
If none of the current Mogre maintainers can provide a reasonable explanation for this, the next step is to breathe deep and delve into the arcane Mogre source code and try to grasp the issue at its root.
A possible hint to consider:
- Ogre is a non-MT safe library
- The garbage collector runs in an independent system thread
- Garbage collection could happen concurrently with the calling of an Ogre function.
- Some concurrency handling failure could lead to exceptions, crashes and generalized strange behaviour.
Best regards,
Gonçalo
Ok, finally I've got it and it's bad, way BAD. There is indeed a bizarre bug with either Ogre or Mogre, but given the larger number of strange uses done with Ogre, for now I think it's the latter. I've found a simple bullet-proof condition for producing null reference pointers on Mogre function creation.
Just smack these two functions on your favorite Mogre sample and watch them blow:
public override void CreateFrameListener()
{
base.CreateFrameListener();
root.FrameStarted += new FrameListener.FrameStartedHandler(root_FrameStarted);
new Thread(delegate()
{
while (!shutDown)
{
// Choose your poison
/*/
byte[] arr = new byte[320 * 240 * 3];
arr[120] = 5;
/*/
GC.Collect();
/**/
Thread.Sleep(66);
}
}).Start();
}
bool root_FrameStarted(FrameEvent evt)
{
SceneNode node = sceneMgr.CreateSceneNode();
sceneMgr.DestroySceneNode(node.Name);
return true;
}
What could this mean? Here's my two cents:
Basically, if you have a Thread which is concurrent with the Mogre thread and is somewhat allocating memory, or worse, freeing memory, Mogre will snap. Keep in mind that it is likely that this will only happen on dual-core machines, but I haven't tested this claim thouroughly.
This could come from a variety of sources, including input handling buffers like keyboard, mouse, video camera threads, etc.
If there is a high memory manipulation from both the Mogre thread and the memory handling thread, Mogre will crash hard, even if the thread is completely independent with nothing to do with Mogre data structures.
If none of the current Mogre maintainers can provide a reasonable explanation for this, the next step is to breathe deep and delve into the arcane Mogre source code and try to grasp the issue at its root.
A possible hint to consider:
- Ogre is a non-MT safe library
- The garbage collector runs in an independent system thread
- Garbage collection could happen concurrently with the calling of an Ogre function.
- Some concurrency handling failure could lead to exceptions, crashes and generalized strange behaviour.
Best regards,
Gonçalo