Clearing the scene manager, possible bug?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Handle
Posts: 19
Joined: Tue Jul 13, 2004 2:00 pm

Clearing the scene manager, possible bug?

Post by Handle »

I have a title screen for my Irrlich project in which I can click on a button which then changes to the game. The game is in 3D and hence uses the scene manager.

When I press escape the game returns to the titlr screen, however if I try to start a new game the program then crashes with a Unhandled Exception: System.NullReferenceException.

I have tracked the error down to the section

pMesh = m_pMgr->getMesh(File_BSP);

if(pMesh)
{
m_Node_Map = m_pMgr->addOctTreeSceneNode(pMesh->getMesh(0));

}

the addOctSceneNode(pMesh->getMesh()); is what causes the exception.

what I *think* is happening is that when I clear the scene manager when the game phase exits (m_pMgr->clear()) all the data in the scene manager is getting cleared but the manager is not told that it doesn't have the data files anymore. When pMesh = m_pMgr->getMesh(File_BSP) is called the scene manager is still returning the location in memory where the mesh was previously stored and is NOT loading the mesh in again (I get no file loading comments in the console window).

Anybody know how to clear the scene manager fully so that it will load in files again?

Cheers,

Handle
etcaptor
Posts: 871
Joined: Fri Apr 09, 2004 10:32 pm
Location: Valhalla
Contact:

Post by etcaptor »

I'm not sure that this is related exactly with scene manager. Maybe you must stop event receiver too?
But sometime I use something like this:

Code: Select all

    
    smgr->getRootSceneNode()->getChildren();
    const core::list<ISceneNode*>& children =     smgr->getRootSceneNode()->getChildren();
    core::list<ISceneNode*>::Iterator it = children.begin();

    for (; it != children.end(); ++it)
    {
           ISceneNode* current = *(it);
           if(current)
           {         
              current->setVisible(false);   
              current->remove();
              it = children.begin();
            }
     }
Hope this will help.
Morrog
Posts: 58
Joined: Mon Dec 13, 2004 5:13 am

Post by Morrog »

Well I looked up the code for clear and all it does is call drop on all the scene nodes, which doesn't even affect the meshes.

Code: Select all

//! Removes all children of this scene node
void CSceneManager::removeAll()
{
	ISceneNode::removeAll();
	setActiveCamera(0);
}
The SceneManager inherits partly from ISceneNode (suprise, suprise), which means its a parent to all nodes which don't have a parent (default of NULL, 0)
So this calls:

Code: Select all

//! Removes all children of this scene node
		virtual void removeAll()
		{
			core::list<ISceneNode*>::Iterator it = Children.begin();
			for (; it != Children.end(); ++it)
				(*it)->drop();

			Children.clear();
		}
and drop should cause the node to deconstruct, calling:

Code: Select all

//! Destructor
		virtual ~ISceneNode()
		{
			// delete all children
			core::list<ISceneNode*>::Iterator it = Children.begin();
			for (; it != Children.end(); ++it)
				(*it)->drop();

			// delete all animators
			core::list<ISceneNodeAnimator*>::Iterator ait = Animators.begin();
				for (; ait != Animators.end(); ++ait)
					(*ait)->drop();

			if (TriangleSelector)
				TriangleSelector->drop();
		}
No sign of even touching the mesh.

I think you have a bug elsewhere. Put your project into debug mode if you can and figure out exactly where the crash occurs. And put Irrlicht into debug mode if the crash is happening in there.
Or maybe see what getMesh(0) is returning.
Handle
Posts: 19
Joined: Tue Jul 13, 2004 2:00 pm

Post by Handle »

Thanks to etcaptor & Morrog for the replies, I'll have ago at fixing the problem later today; taking on board your thoughts and will post the results.
Post Reply