Weird behavior with creating/destroying scene managers

Discussion area about developing with Ogre2 branches (2.1, 2.2 and beyond)
Post Reply
User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia
x 81

Weird behavior with creating/destroying scene managers

Post by Mind Calamity »

I wrote this little test just to try things out, and OGRE seems to be freezing after a few iterations.

Here's the code:

Code: Select all

#include "Ogre.h"
#include <iostream>

int main() {
	for (int i = 0; i < 10; i++)
	{
		Ogre::Root root;

		if (!root.showConfigDialog()) return -1;

		root.initialise(true);
		for (int j = 0; j < 512; j++)
		{
			printf("\rLoop %d Iteration %d", i, j);
			Ogre::SceneManager* mgr = root.createSceneManager(Ogre::ST_GENERIC, 2, Ogre::INSTANCING_CULLING_SINGLETHREAD, "test");
			root.destroySceneManager(mgr);
		}
	}
	return 0;
}
Extremely simple, yet it freezes after a few iterations (or sometimes a single iteration), and in the case of my framework which has several wrapper classes - crashes only in Release in ArrayMemoryManager.cpp in the initialize method (line 108 in my version of the code, at the iteration) and it seems like the ArrayMemoryManager itself is null, going up in the call stack it seems to be at the creation of the root scene node, but it's after a lot more iterations than seems to take with vanilla OGRE, and it's not a freeze, but a crash.

Here's an image of the crash in my case, which includes a stack trace (as much as you can see of it)

The code I use is very similar, I just have 1 class that has a SceneManager member and I basically just do the same thing in the code above.

Here's a video I made showing the behavior:
[youtube]xtiResWgLCY[/youtube]

Dropbox link to precompiled demo.

Extremely inconsistent and probably buggy behavior.

Should I file this as a bug ?

Edit: I'm at the following commit: https://bitbucket.org/sinbad/ogre/commi ... 332e557622
BitBucket username changed to iboshkov (from MindCalamity)
Do you need help? What have you tried?
- xavier
---------------------
HkOgre - a Havok Integration for OGRE | Simple SSAO | My Blog | My YouTube | My DeviantArt

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4211
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 802
Contact:

Re: Weird behavior with creating/destroying scene managers

Post by dark_sylinc »

Thanks.

Yes this is a race condition. I tried it out and realized what's wrong.

The loop does:

Code: Select all

while( !mExitWorkerThreads )
{
    mWorkerThreadsBarrier->sync();
    if( !mExitWorkerThreads )
    {
        mWorkerThreadsBarrier->sync();
    }
}
But if the worker thread hasn't been fully spawned yet, it will reach "while( !mExitWorkerThreads )", see mExitWorkerThreads is true, never hit "mWorkerThreadsBarrier->sync()"; while the SceneManager is frozen in

Code: Select all

    mExitWorkerThreads = true;
    mWorkerThreadsBarrier->sync(); // Wake up worker threads so they stop
trying to wake up a thread that never went to sleep.
Adding a Ogre::Threads::Sleep( 10 ) between creating and destroying the SceneManager helps masking the problem.

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4211
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 802
Contact:

Re: Weird behavior with creating/destroying scene managers

Post by dark_sylinc »

Fixed. Try again now.

User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia
x 81

Re: Weird behavior with creating/destroying scene managers

Post by Mind Calamity »

Yep, that fixed it. Thanks for the prompt reply and fix. :)

My framework still seems to be crashing in ArrayMemoryManager (which is null), but that seems unrelated.
BitBucket username changed to iboshkov (from MindCalamity)
Do you need help? What have you tried?
- xavier
---------------------
HkOgre - a Havok Integration for OGRE | Simple SSAO | My Blog | My YouTube | My DeviantArt

Post Reply