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
Clearing the scene manager, possible bug?
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:
Hope this will help.
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();
}
}
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.
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:
and drop should cause the node to deconstruct, calling:
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.
Code: Select all
//! Removes all children of this scene node
void CSceneManager::removeAll()
{
ISceneNode::removeAll();
setActiveCamera(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();
}
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();
}
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.