new instance manager, instance not removed

Problems building or running the engine, queries about how to use features etc.
Post Reply
Nickak2003
Goblin
Posts: 272
Joined: Thu Jun 10, 2004 4:19 am
x 26

new instance manager, instance not removed

Post by Nickak2003 »

I am using the new instance manager. I create some instances, then I delete some instances. The deleted instances remain visible unless I update the position/orientation of an existing instance. I think I must be not calling something important?
Here is how I delete stuff:

Code: Select all

	

void GraphicalObject::destroy(Graphics* graphics) {
	
	if (mSN) {
		mSN->detachAllObjects();
		mSN->getParentSceneNode()->removeAndDestroyChild(mSN);

		if (mObj) {
			Ogre::Entity* ent = dynamic_cast<Ogre::Entity*>(mObj);
			graphics->getSceneManager()->destroyEntity(ent);
		}		
		else // does dynamic cast return nullptr?
			EXCEPT << "GraphicalObject::destroy non-instanced obj is nullptr";

		mSN = nullptr;
	}
	else if (mObj) {
		//THIS IS THE INSTANCED ENTITY AREA - Everything clears up on myside, I think, but on ogre the ent remains visible!
		Ogre::InstancedEntity* ent = dynamic_cast<Ogre::InstancedEntity*>(mObj); // mObj is a Ogre::MovableObject*
		graphics->getSceneManager()->destroyInstancedEntity(ent);
	}
	else
		EXCEPT << "GraphicalObject::destroy instanced obj is nullptr";
	
	mObj = nullptr;
}
Everything clears up on myside, I think, but on ogre the ent remains visible!
Nickak2003
Goblin
Posts: 272
Joined: Thu Jun 10, 2004 4:19 am
x 26

Re: new instance manager, instance not removed

Post by Nickak2003 »

Ok, in the new instancing sample, i replaced the defrag button function with the following,

Code: Select all

	mSceneMgr->destroyInstancedEntity(dynamic_cast<Ogre::InstancedEntity*>(mEntities[0]));
	mEntities.erase(mEntities.begin());
and removing works ok, so it must be something im doing, sorry

edit- scratch that, that test was with shader based.
With an actual program based, it does not work, is this because of lack of scene nodes only?
So i put that code in a button, select a program op, and change to 4x4, scene nodes off, hit button, all remain, is this how it is supposed to work when scene nodes are not in use?
Nickak2003
Goblin
Posts: 272
Joined: Thu Jun 10, 2004 4:19 am
x 26

Re: new instance manager, instance not removed

Post by Nickak2003 »

Ok, I have done further testing, and the problem is only with the VTF method. Other methods work OK.
The solution for the VTF seems to be changing any position such as with the following code:

Code: Select all

	Ogre::InstancedEntity* ent = dynamic_cast<Ogre::InstancedEntity*>(mEntities[0]);
	mSceneMgr->destroyInstancedEntity(ent);
	mEntities.erase(mEntities.begin());

	ent = dynamic_cast<Ogre::InstancedEntity*>(mEntities.back());
	ent->setPosition(ent->getPosition()); //do some sort of refresh
I do think it would be better if it automatically refreshed, though.
Post Reply