Why does my code crash?

Started by
4 comments, last by CodeTitan 18 years, 11 months ago

#include "ExampleApplication.h"

Real x = 0.0f;
Real y = 0.0f;
Real z = 0.0f;

class TutorialFrameListener :	public ExampleFrameListener, public MouseMotionListener, public MouseListener
{
public:
    TutorialFrameListener( RenderWindow* win, Camera* cam, SceneManager *sceneMgr )
        : ExampleFrameListener(win, cam, true, true)
    {
		mCamNode = cam->getParentSceneNode( )->getParentSceneNode( );
        mSceneMgr = sceneMgr;
        mEventProcessor->addMouseListener( this );
        mEventProcessor->addMouseMotionListener( this );		
    }
	// MouseDragged
	void mouseMoved(MouseEvent* e) { }
	void mouseDragged(MouseEvent* e) { }

	// MouseListener
	void mouseClicked(MouseEvent* e) { }
	void mouseEntered(MouseEvent* e) { }
	void mouseExited(MouseEvent* e) { }

	void mousePressed(MouseEvent* e) {
		if ( e->getButtonID() & MouseEvent::BUTTON0_MASK )
		{
			x = e->getX();
			y = e->getY();
		}
	}
	void mouseReleased(MouseEvent* e) { }

    bool frameStarted(const FrameEvent &evt)
    {
        return ExampleFrameListener::frameStarted( evt );
    }
protected:
    SceneManager *mSceneMgr;   // The current SceneManager
    SceneNode *mCamNode;   // The SceneNode the camera is currently attached to
};

class TutorialApplication : public ExampleApplication
{
public:
    TutorialApplication()
    {
    }

    ~TutorialApplication() 
    {
    }
protected:
    void createCamera(void)
    {
		mCamera = mSceneMgr->createCamera("PlayerCam"); 
		mCamera->setNearClipDistance(5);
    }

    void createScene(void)
    {
		 mSceneMgr->setAmbientLight( ColourValue( 1, 1, 1 ) );
		 Entity *ent1 = mSceneMgr->createEntity( "Robot", "robot.mesh" );
		 SceneNode *node1 = mSceneMgr->getRootSceneNode()->createChildSceneNode( "RobotNode" );
		 node1->attachObject( ent1 );
		 node1->setPosition(x, y, z);
    }

    void createFrameListener(void)
    {
		// Create the FrameListener
        mFrameListener = new TutorialFrameListener(mWindow, mCamera, mSceneMgr);
        mRoot->addFrameListener(mFrameListener);

        // Show the frame stats overlay
        mFrameListener->showDebugOverlay(false);
    }
};

#if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"

INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
int main(int argc, char **argv)
#endif
{
    // Create application object
    TutorialApplication app;

    try {
        app.go();
    } catch( Exception& e ) {
#if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32
        MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
        fprintf(stderr, "An exception has occured: %s\n",
                e.getFullDescription().c_str());
#endif
    }

    return 0;
}

[Edited by - CodeTitan on May 12, 2005 2:00:24 PM]
Advertisement
Try using source tags instead of code tags.
HxRender | Cornerstone SDL TutorialsCurrently picking on: Hedos, Programmer One
I've narrowed down the error to the TutorialFrameListener class, and I believe it has something to do with Reals (floats).
I checked my debug exceptions, and it said there was a float divide by zero exception.
That's funny cause I don't see any division operators...
HxRender | Cornerstone SDL TutorialsCurrently picking on: Hedos, Programmer One
The one line that looks suspicious to me is:

mCamNode = cam->getParentSceneNode( )->getParentSceneNode( );

Did you make that or get that from an example? I would think that it should be:

mCamNode = cam->getParentSceneNode( );

Also check your Ogre.log where your .exe is and see if you can find the actual error in there.
Quote:Original post by Drew_Benton
The one line that looks suspicious to me is:

mCamNode = cam->getParentSceneNode( )->getParentSceneNode( );

Did you make that or get that from an example? I would think that it should be:

mCamNode = cam->getParentSceneNode( );

Also check your Ogre.log where your .exe is and see if you can find the actual error in there.


Drew_Benton, I love you!

This is the millionth time you've solved my problem.

Yes - it was the getParentSceneNode()->getParentSceneNode() that was causing the problems.

This topic is closed to new replies.

Advertisement