[Ogre 2.0, SOLVED] Crash After Attaching Camera to SceneNode

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


Post Reply
User avatar
excaliburHisSheath
Gnoblar
Posts: 18
Joined: Sat Feb 15, 2014 8:06 pm

[Ogre 2.0, SOLVED] Crash After Attaching Camera to SceneNode

Post by excaliburHisSheath »

UPDATE: DISREGARD THIS POST

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 :roll:.

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);
        }
    }
It crashes at if( mParent ) because `this` is null. I traced the problem up to Camera::isViewOutOfDate():

Code: Select all

    bool Camera::isViewOutOfDate(void) const
    {
        const Quaternion derivedOrient( mParentNode->_getDerivedOrientationUpdated() );
        const Vector3 derivedPos( mParentNode->_getDerivedPosition() );
In this case mParentNode is null which is leading to the crash.

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 );
		}
And here's the code where I create the "Transform" component, which is where I am creating the SceneNode that the camera is being attached to:

Code: Select all

		Transform::Transform( const Scene& scene )
			: node( nullptr )
		{
			Ogre::SceneManager& sceneManager = scene.sceneManager();
			node = sceneManager.createSceneNode();
			sceneManager.getRootSceneNode()->addChild( node );
		}
I appreciate any help you can offer. I can work around this for the time being by moving the camera directly, but I'd prefer to not have to treat the camera as a special case.

Thanks!
Post Reply