Jump to content
  • Advertisement
Sign in to follow this  
CodeTitan

Why does my code crash?

This topic is 4912 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

#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]

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!