Fix for using multiple Ogre::SceneManager

Mind

23-05-2010 00:20:29

Hi,

i have fix the crash if using multiple SceneManager on differend PagedGeometry instances.
Not supported is swaping SceneManager for one PagedGeometry instance or better i say, don't know what happend if somone try this ;-)


i use version 1.10 which is available as zip download.



Index: ImpostorPage.h
===================================================================
@@ -197,7 +197,8 @@
static Ogre::ColourValue impostorBackgroundColor;
static Ogre::BillboardOrigin impostorPivot;

- static Ogre::uint32 selfInstances;
+ static Ogre::uint32 selfInstances;
+ static std::map<Ogre::SceneManager *, Ogre::uint32> refSceneManager;
static Ogre::uint32 updateInstanceID;
Ogre::uint32 instanceID;

Index: ImpostorPage.cpp
===================================================================
@@ -31,7 +31,9 @@
//-------------------------------------------------------------------------------------

uint32 ImpostorPage::selfInstances = 0;
+std::map<Ogre::SceneManager *, Ogre::uint32> ImpostorPage::refSceneManager;

+
int ImpostorPage::impostorResolution = 128;
ColourValue ImpostorPage::impostorBackgroundColor = ColourValue(0.0f, 0.3f, 0.0f, 0.0f);
BillboardOrigin ImpostorPage::impostorPivot = BBO_CENTER;
@@ -39,19 +41,30 @@

void ImpostorPage::init(PagedGeometry *geom, const Ogre::Any &data)
{
+ uint32 refCount = 1;
+
//Save pointers to PagedGeometry object
sceneMgr = geom->getSceneManager();
this->geom = geom;

//Init. variables
setBlendMode(ALPHA_REJECT_IMPOSTOR);
-
- if (++selfInstances == 1){
+
+
+ if (++selfInstances == 1){
+ ResourceGroupManager::getSingleton().createResourceGroup("Impostors");
+ }
+
+ std::map<SceneManager *, uint32>::iterator iter = refSceneManager.find(sceneMgr);
+ if (iter == refSceneManager.end()) {
//Set up a single instance of a scene node which will be used when rendering impostor textures
geom->getSceneNode()->createChildSceneNode("ImpostorPage::renderNode");
- geom->getSceneNode()->createChildSceneNode("ImpostorPage::cameraNode");
- ResourceGroupManager::getSingleton().createResourceGroup("Impostors");
- }
+ geom->getSceneNode()->createChildSceneNode("ImpostorPage::cameraNode");
+
+ refSceneManager.insert(std::pair<SceneManager*, uint32>(sceneMgr,refCount));
+ } else {
+ ++iter->second;
+ }
}

ImpostorPage::~ImpostorPage()
@@ -63,11 +76,19 @@
delete ibatch;
}

- if (--selfInstances == 0){
- sceneMgr->destroySceneNode("ImpostorPage::renderNode");
- sceneMgr->destroySceneNode("ImpostorPage::cameraNode");
+ std::map<SceneManager *, uint32>::iterator iter2 = refSceneManager.find(sceneMgr);
+ if (iter2 != refSceneManager.end()) {
+ if(--iter2->second == 0) {
+ sceneMgr->destroySceneNode("ImpostorPage::renderNode");
+ sceneMgr->destroySceneNode("ImpostorPage::cameraNode");
+
+ refSceneManager.erase(iter2);
+ }
+ }
+
+ if (--selfInstances == 0){
ResourceGroupManager::getSingleton().destroyResourceGroup("Impostors");
- }
+ }
}



It will be nice, if someone can add this fix for future releases.

Mind.

tdev

23-05-2010 11:21:46

thanks! will have a look at it.

btw, posting patches at redmine is the preferred way: http://redmine.rigsofrods.org/projects/pagedgeometry

Mind

26-05-2010 19:52:22

Hi,

ok next one i post it on this side.

Sorry i had a error in my code the ResourceGroup for Ogre should only one times created, not each SceneManager ...
I fixed it and edit in my first post.

Mind.