jguerra
29-03-2008 19:10:17
Hi.
I've found a bug in PLSM2 when i was trying to destroy cameras. Happily i found a solution for the problem.
So, if you ever want to destroy a camera (destroyCamera()) under plsm, you should make the following changes to PLSM2 code. Don't know if this is the cleanest solution, but i guess it isn't that bad.
OgrePagingLandScapeOctreeSceneManager.cpp
OgrePagingLandScapeSceneManager.cpp
The bind of virtual functions is done dynamically (late binding), and due to the sequence of virtual calls done when OgrePagingLandScapeSceneManager::destroyCamera() is called, the runtime execution loses reference to the parent function implementation (in OgrePagingLandScapeOctreeSceneManager), binding it back to OgrePagingLandScapeSceneManager instead of binding it to SceneManager. Entering a recursive cycle and eventually crashing due to stack overload.
Hope this helps,
jguerra.
*EDIT: Forgot to correct the destroyCamera(const String& name) function on OgrePagingLandScapeOctreeSceneManager.cpp
I've found a bug in PLSM2 when i was trying to destroy cameras. Happily i found a solution for the problem.
So, if you ever want to destroy a camera (destroyCamera()) under plsm, you should make the following changes to PLSM2 code. Don't know if this is the cleanest solution, but i guess it isn't that bad.
OgrePagingLandScapeOctreeSceneManager.cpp
void PagingLandScapeOctreeSceneManager::destroyCamera(Camera *cam)
{
unregisterCamera (static_cast <PagingLandScapeOctreeCamera *> (cam));
SceneManager::destroyCamera(cam); //COMMENT OR DELETE THIS LINE
}
void PagingLandScapeOctreeSceneManager::destroyCamera(const String& name)
{
// Find in list
CameraList::iterator i = mCameras.find(name);
if (i != mCameras.end())
{
destroyCamera(i->second); //COMMENT OR DELETE THIS LINE
unregisterCamera (static_cast <PagingLandScapeOctreeCamera *> (i->second)); //ADD THIS LINE
}
}
OgrePagingLandScapeSceneManager.cpp
void PagingLandScapeSceneManager::destroyCamera(Camera *cam)
{
if (mOptions->primaryCamera && cam->getName() == mOptions->primaryCamera->getName())
{
mOptions->setPrimaryCamera (0);
}
#ifndef _PLSM_OCTREE
OctreeSceneManager::destroyCamera(cam);
#else //_PLSM_OCTREE
PagingLandScapeOctreeSceneManager::destroyCamera(cam);
SceneManager::destroyCamera(cam); //ADD THIS LINE
#endif //_PLSM_OCTREE
}
//-----------------------------------------------------------------------
void PagingLandScapeSceneManager::destroyCamera(const String& name)
{
if (mOptions->primaryCamera && name == mOptions->primaryCamera->getName())
{
mOptions->setPrimaryCamera (0);
}
#ifndef _PLSM_OCTREE
OctreeSceneManager::destroyCamera(name);
#else //_PLSM_OCTREE
PagingLandScapeOctreeSceneManager::destroyCamera(name);
SceneManager::destroyCamera(name); //ADD THIS LINE
#endif //_PLSM_OCTREE
}
The bind of virtual functions is done dynamically (late binding), and due to the sequence of virtual calls done when OgrePagingLandScapeSceneManager::destroyCamera() is called, the runtime execution loses reference to the parent function implementation (in OgrePagingLandScapeOctreeSceneManager), binding it back to OgrePagingLandScapeSceneManager instead of binding it to SceneManager. Entering a recursive cycle and eventually crashing due to stack overload.
Hope this helps,
jguerra.
*EDIT: Forgot to correct the destroyCamera(const String& name) function on OgrePagingLandScapeOctreeSceneManager.cpp