Simple Application crahes. What am I doing wrong??

GoatW_

26-05-2008 02:23:16

Hi everybody,

I'm trying to get a simple application with an ogrehead.mesh running but I'm surely missing something really important :wink:

I know that my code crashes in Application::frameEnded 'cause it exits with code 0x04... BTW I'm using NxOgre 1.0.


#define WIN32
#include"Ogre.h"
#include<NxOgre.h>
#include"OIS/OIS.h"


using namespace Ogre;
using namespace NxOgre;



class Application : public Ogre::FrameListener
{
public:
Root* pRoot ;
RenderWindow* pRenderWindow;
SceneManager* pSceneManager;
Camera* pCamera;
Viewport* pViewport;
float pTime;
OIS::InputManager *pInputManager;
OIS::Mouse *pMouse;
OIS::Keyboard *pKeyboard;
NxOgre::World* mWorld;



public :
Application();
~Application();
void run();
virtual bool frameStarted(const Ogre::FrameEvent& evt);
virtual bool frameEnded(const Ogre::FrameEvent& evt);

};

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

#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else

int main(int argc, char *argv[])
#endif
{

try
{

Application* app = new Application;
app->run() ;
}

catch( Ogre::Exception& e )
{
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
MessageBoxA( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
std::cerr << "An exception has occured: " <<< std::endl;
#endif
}

return 0;
}
Application::Application()
{
//creation de l’objet Root
pRoot = new Ogre::Root();

if(!pRoot->restoreConfig())
{
if(!pRoot->showConfigDialog())
{
}
}

//initialisation de la fenêtre de rendu
pRenderWindow=pRoot->initialise(true,"Ma premiere application Ogre");

//initialisation du gestionnaire de scene
pSceneManager=pRoot->createSceneManager(ST_GENERIC,"MonGestionnaireDeScene");

//initialisation de la camera
pCamera = pSceneManager->createCamera("MaCamera");
pCamera->setPosition(Ogre::Vector3(100,0,0));
pCamera->lookAt(Ogre::Vector3(0,0,0));

//creation du viewport
pViewport = pRenderWindow->addViewport(pCamera);

//initialisation des ressources
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../../media/models","FileSystem","General");
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../../media/materials/scripts","FileSystem","General");
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../../media/materials/textures","FileSystem","General");
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../../media/materials/programs","FileSystem","General");
Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

//PHYSIQUE avec PhysX

//INITIALISATION DE LA PHYSIQUE
mWorld = new NxOgre::World("FrameListener: Yes, log: no");
NxOgre::Scene* mScene = mWorld->createScene("Paris", "gravity: yes, floor: yes, controller: accumulator, renderer: ogre, rendererUserData: pSceneManager");



//creation d’une entitée PHYSIQUE
Ogre::Entity* entity = pSceneManager->createEntity("Hello", "OgreHead.mesh");
mScene->createBody("Nom", new NxOgre::Cube(0.5f,0.5f,0.5f), Ogre::Vector3(5,3000,5), "model: Hello, model-type: reference", "mass: 50");

//FRAMELISTENER

//enregistrement du FrameListener
pRoot->addFrameListener(this);

pTime=0;

//INPUT

//initialisation de OIS,le systeme d’entrée du clavier et sourie
OIS::ParamList pl;
size_t windowHnd = 0;
std::ostringstream windowHndStr;
pRenderWindow->getCustomAttribute("WINDOW", &windowHnd);
windowHndStr << windowHnd;

pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
pInputManager = OIS::InputManager::createInputSystem( pl );

pMouse = static_cast<OIS::Mouse*>(pInputManager->createInputObject(OIS::OISMouse, false));
pKeyboard = static_cast<OIS::Keyboard*>(pInputManager->createInputObject(OIS::OISKeyboard, false));

//la sourie ne doit pas sortire de l’écran…
unsigned int width, height, depth;
int top, left;
pRenderWindow->getMetrics(width, height, depth, left, top);
const OIS::MouseState &ms = pMouse->getMouseState();
ms.width = width;
ms.height = height;



};

Application::~Application()
{
delete mWorld;
delete pRoot;
};
void Application::run()
{
pRoot->startRendering();
};

bool Application::frameStarted(const FrameEvent& evt)
{
pKeyboard->capture();
if (pKeyboard->isKeyDown(OIS::KC_ESCAPE)) return false;

return true;
}

bool Application::frameEnded(const FrameEvent& evt)
{
pTime += evt.timeSinceLastFrame;

if (pTime>10.0)
{
exit(4);
return false;
};

return true;
}



Thank you very much :oops:

betajaen

26-05-2008 11:07:28

Try dropping this "rendererUserData: pSceneManager" from the SceneParams, and your World params are using the old style stuff. It goes "time-controller: ogre"

Also a stack trace without that exit(4) would be also useful.

GoatW_

26-05-2008 21:12:37

Thank you very much betajaen :wink: .
Your advises partially solved my problem but the app was still running incorrectly.
I downloaded your cake and used it as "tutorial".

Thank you very much!


BTW. Your cake tastes good :wink: .