Multiple SceneManager issue - Ogre 1.7.2

Discussion area about developing or extending OGRE, adding plugins for it or building applications on it. No newbie questions please, use the Help forum for that.
Post Reply
MattStevens
Goblin
Posts: 239
Joined: Mon Apr 07, 2008 10:27 pm
x 4

Multiple SceneManager issue - Ogre 1.7.2

Post by MattStevens »

Lately I came across this issue when rendering 2 different scenes in 2 different scene managers that are using the same materials.

Symptom: When running in debug, I get the assert in function QueuedRenderableCollection::addRenderable in the OgreRenderQueueSortingGrouping.cpp file. In release, there's memory leaks.

The issue is related to the RenderQueue cleanup when Passes are tagged as dirty. The usual behavior is that the Ogre::RenderPriorityGroup are cleared by the Ogre::RenderQueue at the beginning of a render to remove the dirty Ogre::Pass from the QueuedRenderableCollection::mGrouped map. (See RenderPriorityGroup::clear in OgreRenderQueueSortingGrouping.cpp) If this is not done, and the Pass's hash changed, the mGrouped map's key will be messed up and troubles happen. This works perfectly when using a single SceneManager, not when using 2 or more. The reason is that the dirty Pass list is static and cleared by the RenderQueue and by having 2 SceneManager you have 2 RenderQueue. With the current code, only 1 RenderQueue will be able to clean itself correctly, and the second one will cause a lot of troubles (Likely crash, memory leak or assert).

I tried to explain the problem as clearly as possible, if it is not clear enough I'll gladly give more informations.

Now onto the solution.

I fixed it in a pretty ugly way, in my opinion, but I could not rewrite a lot of code so this is a straight-forward fix.

I added a static list that contains all the render queues. The RenderQueue::clear function is now a static one. What it does is first, it calls for every RenderQueue a new function called doClear that does the job of clearing the groups correctly. Then, it will call the static Pass::processPendingPassUpdates() function that will clear the static msDirtyHashList list.

This fix worked for me and doesn't seem to add any more problems. I don't know how to generate a patch file, especially since I have a couple other modifications in my Ogre version, but if needed I can give you my changes precisely.

- Matt

bstone
OGRE Expert User
OGRE Expert User
Posts: 1920
Joined: Sun Feb 19, 2012 9:24 pm
Location: Russia
x 199

Re: Multiple SceneManager issue - Ogre 1.7.2

Post by bstone »

Here's what I see in v1.8.1 of RenderPriorityGroup::clear()

Code: Select all

        // NB we do NOT clear the graveyard or the dirty list here, because 
        // it needs to be acted on for all groups, the parent queue takes 
        // care of this afterwards
I believe that have been fixed in the later versions.

MattStevens
Goblin
Posts: 239
Joined: Mon Apr 07, 2008 10:27 pm
x 4

Re: Multiple SceneManager issue - Ogre 1.7.2

Post by MattStevens »

No, I have this comment in version 1.7.2 also.

What it means is that it clears every RenderPriorityGroup of every RenderQueueGroup, and then clear the dirty and graveyard list in the RenderQueue. That's the correct behavior assuming you have only 1 RenderQueue but it breaks when you have 2 or more because the dirty and graveyard list will be cleared before the 2nd RenderQueue gets cleaned correctly.

- Matt

bstone
OGRE Expert User
OGRE Expert User
Posts: 1920
Joined: Sun Feb 19, 2012 9:24 pm
Location: Russia
x 199

Re: Multiple SceneManager issue - Ogre 1.7.2

Post by bstone »

Oh, all right. Should be worth raising up an issue in the bug tracker then and referring this thread in the description.

MattStevens
Goblin
Posts: 239
Joined: Mon Apr 07, 2008 10:27 pm
x 4

Re: Multiple SceneManager issue - Ogre 1.7.2

Post by MattStevens »

Yeah done, I created an issue in bug tracker about this.

User avatar
lf3thn4d
Orc
Posts: 478
Joined: Mon Apr 10, 2006 9:12 pm
x 12

Re: Multiple SceneManager issue - Ogre 1.7.2

Post by lf3thn4d »

I believe this issue is partially related to this as well:
http://www.ogre3d.org/forums/viewtopic. ... nder+queue

MattStevens
Goblin
Posts: 239
Joined: Mon Apr 07, 2008 10:27 pm
x 4

Re: Multiple SceneManager issue - Ogre 1.7.2

Post by MattStevens »

This is exactly the same issue. I can't believe I didn't found it before.

Looks like I was wrong and this was already fixed. At least it is in Ogre 1.8.2. How did you go to fix your problem ? From what I understand since your RenderQueue was not created from a SceneManager, it would not be cleared. How I fixed this issue in my version is I added a new static list that contains all RenderQueues (adding and removing from the list in the RenderQueue constructor and destructor), and I loop in this list in RenderQueue::clear instead of get the SceneManagerIterator so it would work in your case as well.

- Matt

User avatar
lf3thn4d
Orc
Posts: 478
Joined: Mon Apr 10, 2006 9:12 pm
x 12

Re: Multiple SceneManager issue - Ogre 1.7.2

Post by lf3thn4d »

Yeah. It's been a while since I complained about it. I did a workaround and forgot about it. It's something that needs to be fixed but I don't know the right way yet. Maybe we can pool in our use cases and find a middle ground that works for both our cases. The way I worked around it was to just iterate through the internal RenderQueueGroup list and call clear manually for each of them. I was quite dumb founded when I found out it only clear renderqueues that are registered in the scenemanager and actually clears EVERY one of them :shock:. Definitely a wrong behavior for a RenderQueue::clear() function.

I'm believe the problem in question is the behavior on how dirty passes are handled. Maybe the solution is to fix that instead of hacking around the RenderQueue::clear() function.

MattStevens
Goblin
Posts: 239
Joined: Mon Apr 07, 2008 10:27 pm
x 4

Re: Multiple SceneManager issue - Ogre 1.7.2

Post by MattStevens »

You are probably right that it should be the dirty pass handling that we fix, however it probably requires a good amount of changes. Perhaps it will be done with the SceneManager revamp in future version ?

Post Reply