It turns out the destructor on my "Transform" component was getting called, which was causing it to destroy scene nodes and detach objects. Sometimes this resulted in a hard crash, sometimes this meshes mysteriously disappeared. Once I fixed the problem everything went back to working as expected. Of course I didn't figure it out until after posting for help .
Thanks anyway, folks.
-----------------------------------------------------
I'm running into a crash deep in renderOneFrame() which is only happening when I detach the camera in my scene from the root node and attach it to another node. The crash happens in Node::_updateFromParent():
Code: Select all
void Node::_updateFromParent(void)
{
if( mParent )
mParent->_updateFromParent();
updateFromParentImpl();
// Call listener (note, this method only called if there's something to do)
if (mListener)
{
mListener->nodeUpdated(this);
}
}
Code: Select all
bool Camera::isViewOutOfDate(void) const
{
const Quaternion derivedOrient( mParentNode->_getDerivedOrientationUpdated() );
const Vector3 derivedPos( mParentNode->_getDerivedPosition() );
Here is the code I'm using to create the camera:
Code: Select all
Camera::Camera( const Scene& scene,
Transform& transform,
const char* cameraName )
{
// create camera and add it to scene heirarchy
camera = scene.sceneManager().createCamera( cameraName );
// This leads the the crash
camera->detachFromParent();
transform.node->attachObject( camera );
// setting the position on the camera directly doesn't cause a problem
// camera->setPosition( 0.0f, 0.0f, 10.0f );
// camera->lookAt( 0.0f, 0.0f, 0.0f );
camera->setNearClipDistance( 0.5f );
camera->setFarClipDistance( 1000.0f );
// setup the camera's compositor
// each camera gets a workspace.
// This probably isn't a good idea.
Ogre::CompositorManager2* pCompositorManager =
scene.ogreRoot().getCompositorManager2();
const Ogre::String workspaceName = "scene workspace";
const Ogre::IdString workspaceID( workspaceName );
pCompositorManager->createBasicWorkspaceDef( workspaceID,
Ogre::ColourValue::Red );
pCompositorManager->addWorkspace( &scene.sceneManager(),
&scene.renderWindow(),
camera,
workspaceID,
true );
}
Code: Select all
Transform::Transform( const Scene& scene )
: node( nullptr )
{
Ogre::SceneManager& sceneManager = scene.sceneManager();
node = sceneManager.createSceneNode();
sceneManager.getRootSceneNode()->addChild( node );
}
Thanks!