Crash with NxOgre::Body* @ runtime

Rasengan

08-07-2008 10:08:20

Hello!

My application crash @ runtime when i try to use a body directly, so i use an actor and update a sceneNode according actor updates.

I'm using NxOgre 1.0 r21 and Ogre 1.4.8
The problem is the same with the build of Ogre SDK or Ogre SRC.

betajaen

08-07-2008 10:12:41

Crashing indicates you did something wrong. Show us your code and your log files.

Rasengan

08-07-2008 10:31:29


...
void createNxWorld(void)
{
// Physics params.
NxOgre::PhysXParams physXParams;
physXParams.setToDefault();

//tell NxOgre to use Ogre as time controller(use frameListener)
physXParams.mTimeController = NxOgre::PhysXParams::TC_OGRE;

//tell NxOgre to create a log
physXParams.mUseLog = true;

//create the World
mWorld = new NxOgre::World(physXParams);

// Link to the remote debugger.
mWorld->getPhysXDriver()->createDebuggerConnection();
}

void createNxScene(void)
{
NxOgre::SceneParams sceneParams;
sceneParams.setToDefault();

//tell NxOgre that there is a gravity
sceneParams.mGravity = NxVec3(0,-9.8,0);

//tell NxOgre to put a floor
sceneParams.mFloor = true;

//create the Scene
mScene = mWorld->createScene("Main Scene", mSceneMgr, sceneParams);
}

void createActorTest(void)
{
NxOgre::ActorParams actorParams;

actorParams.setToDefault();
actorParams.mMass = 10.0f;
actorParams.mDensity = 10.0f;

//g_actor = mScene->createActor("Test Actor", new NxOgre::Sphere(g_ogreHead->getBoundingRadius()), Vector3(0,0,0), actorParams);
g_body = mScene->createBody("ogrehead.mesh", new NxOgre::Sphere(g_ogreHead->getBoundingRadius()), Vector3(0,0,0), actorParams);

}



and in the createScene


virtual void createScene(void)
{
// Set ambient light
mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));

// Create a light
Light* l = mSceneMgr->createLight("MainLight");
l->setPosition(20,80,50);

/*g_ogreHead = mSceneMgr->createEntity("Head", "ogrehead.mesh");
g_headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
g_headNode->attachObject(g_ogreHead);*/

// Create PhysX stuff.
createNxWorld();
createNxScene();
createCameraActor();


createActorTest();

}

betajaen

08-07-2008 10:56:02

First; just give the mass or density and not both. It confuses PhysX:

actorParams.setToDefault();
actorParams.mMass = 10.0f;


Are you positive you have ogrehead.mesh (Of all meshes you had to pick the one that is the size of a small planet) in your resources folder?

And this part looks iffy; If you have the create code commented out in another function. It would call a random pointer causing a crash.

g_ogreHead->getBoundingRadius()

Rasengan

08-07-2008 11:21:51

First; just give the mass or density and not both. It confuses PhysX:

actorParams.setToDefault();
actorParams.mMass = 10.0f;


:wink:


Are you positive you have ogrehead.mesh (Of all meshes you had to pick the one that is the size of a small planet) in your resources folder?

Yes, the head is in ressources folder. (ressources.cfg ok)

And this part looks iffy; If you have the create code commented out in another function. It would call a random pointer causing a crash.

g_ogreHead->getBoundingRadius()


Sry, I have put the comment quickly before pasting the code, anyway the problem 's still there. The exception occur when Nx try to "Set the pose":


/////////////////////////////////////////////////////////////

void RenderableSource::render_Absolute(const TimeStep& ts) {
mRenderPose = getSourcePose(ts);
mRenderable->setPose(mRenderPose);
}

/////////////////////////////////////////////////////////////

betajaen

08-07-2008 11:41:41

The renderable isn't being created for some reason.

Try this:

g_body = mScene->createBody("head;ogrehead.mesh", new NxOgre::Sphere(g_ogreHead->getBoundingRadius()), Vector3(0,0,0), actorParams);

Rasengan

08-07-2008 12:45:38

Same exception: mRenderable->setPose(...);

I continue to use actor and nodes, at the moment. :)

Rasengan

08-07-2008 13:14:01

Here is the test class



/*
-----------------------------------------------------------------------------
Filename: TestNxOgre.h
-----------------------------------------------------------------------------

This source file is generated by the Ogre AppWizard.

Check out: http://conglomerate.berlios.de/wiki/doku.php?id=ogrewizards

Based on the Example Framework for OGRE
(Object-oriented Graphics Rendering Engine)

Copyright (c) 2000-2007 The OGRE Team
For the latest info, see http://www.ogre3d.org/

You may use this sample code for anything you like, it is not covered by the
LGPL like the rest of the OGRE engine.
-----------------------------------------------------------------------------
*/
#ifndef __TestNxOgre_h_
#define __TestNxOgre_h_


#include "ExampleApplication.h"
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#include "../res/resource.h"
#endif

#include <NxOgre.h>

//using namespace NxOgre;

// Globals
NxOgre::Actor* g_actor;
NxOgre::Actor* g_cameraActor;
NxOgre::Body* g_body;

SceneNode* g_headNode;
Entity* g_ogreHead;


class TestNxOgreFrameListener : public ExampleFrameListener
{
private:
SceneManager* mSceneMgr;
public:
TestNxOgreFrameListener(SceneManager *sceneMgr, RenderWindow* win, Camera* cam)
: ExampleFrameListener(win, cam), mSceneMgr(sceneMgr)
{
}

bool frameStarted(const FrameEvent& evt)
{
bool ret = ExampleFrameListener::frameStarted(evt);

return ret;
}


bool frameEnded (const FrameEvent& evt)
{

bool ret = ExampleFrameListener::frameEnded(evt);

// hhmm, ok just for test ;)
g_cameraActor->setGlobalPosition(mCamera->getPosition());
g_cameraActor->setGlobalOrientation(mCamera->getOrientation());

// Push the head with camera :)
g_headNode->setPosition(g_actor->getGlobalPositionAsOgreVector3());
g_headNode->setOrientation(g_actor->getGlobalOrientationAsOgreQuaternion());

return ret;
}

};



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

~TestNxOgreApp()
{
destroyNxWorld();
}

protected:

NxOgre::World* mWorld;
NxOgre::Scene* mScene;


virtual void createCamera(void)
{
// Create the camera
mCamera = mSceneMgr->createCamera("PlayerCam");

// Position it at 500 in Z direction
mCamera->setPosition(Vector3(0,80,80));
// Look back along -Z
mCamera->lookAt(Vector3(0,0,0));
mCamera->setNearClipDistance(5);
mCamera->setFOVy(Radian(Degree(70)));
}


virtual bool configure(void)
{
// Show the configuration dialog and initialise the system
// You can skip this and use root.restoreConfig() to load configuration
// settings if you were sure there are valid ones saved in ogre.cfg
if(mRoot->showConfigDialog())
{
// If returned true, user clicked OK so initialise
// Here we choose to let the system create a default rendering window by passing 'true'
mWindow = mRoot->initialise(true);
// Let's add a nice window icon
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
HWND hwnd;
mWindow->getCustomAttribute("WINDOW", (void*)&hwnd);
LONG iconID = (LONG)LoadIcon( GetModuleHandle(0), MAKEINTRESOURCE(IDI_APPICON) );
SetClassLong( hwnd, GCL_HICON, iconID );
#endif
return true;
}
else
{
return false;
}
}


void createNxWorld(void)
{
// Physics params.
NxOgre::PhysXParams physXParams;
physXParams.setToDefault();

//tell NxOgre to use Ogre as time controller(use frameListener)
physXParams.mTimeController = NxOgre::PhysXParams::TC_OGRE;

//tell NxOgre to create a log
physXParams.mUseLog = true;

//create the World
mWorld = new NxOgre::World(physXParams);

// Link to the remote debugger.
mWorld->getPhysXDriver()->createDebuggerConnection();
}

void createNxScene(void)
{
NxOgre::SceneParams sceneParams;
sceneParams.setToDefault();

//tell NxOgre that there is a gravity
sceneParams.mGravity = NxVec3(0,-9.8,0);

//tell NxOgre to put a floor
sceneParams.mFloor = true;

//create the Scene
mScene = mWorld->createScene("Main Scene", mSceneMgr, sceneParams);
}

void createActor(void)
{
NxOgre::ActorParams actorParams;

actorParams.setToDefault();
actorParams.mMass = 10.0f;

g_actor = mScene->createActor("Test Actor", new NxOgre::Sphere(g_ogreHead->getBoundingRadius()), Vector3(0,0,0), actorParams);

// Exception when accessing mRenderable->setPose(...)
//g_body = mScene->createBody("head;ogrehead.mesh", new NxOgre::Sphere(g_ogreHead->getBoundingRadius()), Vector3(0,0,0), actorParams);

}

void createCameraActor(void)
{
NxOgre::Pose actorPose(mCamera->getPosition(), mCamera->getOrientation());

NxOgre::ActorParams actorParams;
actorParams.setToDefault();
actorParams.mMass = 10.0f;
actorParams.mLinearDamping = 10.0f;
actorParams.mAngularDamping = 10.0f;
actorParams.mBodyFlags |= NX_BF_DISABLE_GRAVITY;
//actorParams.mBodyFlags |= NX_BF_FROZEN_ROT;

g_cameraActor = mScene->createActor("Camera Actor", new NxOgre::Sphere(10.0f), actorPose, actorParams);

}


void destroyNxWorld(void)
{
// Destroy to the remote debugger.
mWorld->getPhysXDriver()->destroyDebuggerConnection();

delete mWorld;
}



// Just override the mandatory create scene method
virtual void createScene(void)
{
// Set ambient light
mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));

// Create a light
Light* l = mSceneMgr->createLight("MainLight");
l->setPosition(20,80,50);

g_ogreHead = mSceneMgr->createEntity("Head", "ogrehead.mesh");
g_headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
g_headNode->attachObject(g_ogreHead);

// Create PhysX stuff.
createNxWorld();
createNxScene();
createCameraActor();

createActor();

}

// Create new frame listener
void createFrameListener(void)
{
mFrameListener= new TestNxOgreFrameListener(mSceneMgr, mWindow, mCamera);
mRoot->addFrameListener(mFrameListener);
}
};

#endif // #ifndef __TestNxOgre_h_


At the moment, this code display the OgreHead and the camera is used to push it, actor and node is used.

Body creation crash application.


I'm a new Ogre, NxOgre user, don't shoot me if this code is not clean :)

betajaen

08-07-2008 14:02:09

What does the ogre.log and nxogre log html say?

betajaen

08-07-2008 15:22:56

I know why it's crashing, your not specifiying that you want ogre to be your renderer in your SceneParams.

Rasengan

08-07-2008 16:59:16

I have added :

sceneParams.mRenderer = NxOgre::SceneParams::RN_OGRE;

or :

sceneParams.mRenderer = NxOgre::SceneParams::SceneRendererType::RN_OGRE;
...


but still crash.

The NxOgre html log is empty and Ogre.log finish with that:



...
17:55:28: Finished parsing scripts for resource group General
17:55:28: Parsing scripts for resource group Internal
17:55:28: Finished parsing scripts for resource group Internal


nothing after that in the log file.

but...now the code crash here:

mCurrentGroup = 0;

in "void ResourceGroupManager::initialiseAllResourceGroups(void)".

problem with ressources settings..?

betajaen

08-07-2008 17:27:58

Which is now your code or Ogre causing the crash. Most likely your code. NxOgre limits itself to touching Ogre; only through rubber gloves and only the Scenenodes.

Bob

08-07-2008 22:37:23

Try the Ogre Demos if they crash too, it has something to do with the resources.

I have the same Problem under Windows with nvidia card.

Rasengan

09-07-2008 11:30:07

I use OgreAppWizard to create projects and it seems that the cfg template must be tweaked a little. (.js) (I've just deleted the ::configure method for the moment and some extra code, to get a template like ogre demo apps, maybe creating a NxOgre app template later...).

Now I can see the NxOgre log contents and the application don't crash when trying to load NxOgre::Body*

In fact I've tested Body loading yesterday @ home (PC with ATI Graphics) and the body load succeed!

But now @ work (PC with Nvidia Graphics), application don't crash but here is the NxOgre log:


NxOgre::OgreNodeRenderable::__createNode

Scenenode with identifier 'head' could not be created!


Actors are visible in the remote debugger and PhysX run well.


The NxOgre log says that is the 1.4.4 Ogre version... I'll pick the last ogre src version from svn (nvidia fix), build it and test.

betajaen

09-07-2008 11:34:43

If the head SceneNode couldn't be created. It could be because 'head' already exists. Are you SURE your calling that function once, and don't have a 'head' scenenode.


It would also help if you didn't use a mesh the size of a small planet, and use one of the normal sized ones from Cake.

Rasengan

09-07-2008 11:50:57

The body is created once and no other entity is created.

Here is the code:



/*
-----------------------------------------------------------------------------
Filename: TestNxOgre.h
-----------------------------------------------------------------------------

This source file is generated by the Ogre AppWizard.

Check out: http://conglomerate.berlios.de/wiki/doku.php?id=ogrewizards

Based on the Example Framework for OGRE
(Object-oriented Graphics Rendering Engine)

Copyright (c) 2000-2007 The OGRE Team
For the latest info, see http://www.ogre3d.org/

You may use this sample code for anything you like, it is not covered by the
LGPL like the rest of the OGRE engine.
-----------------------------------------------------------------------------
*/

#include <Ogre.h>
#include <ExampleApplication.h>
#include <NxOgre.h>


#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#include "../res/resource.h"
#endif


// Globals.
NxOgre::Actor* gCameraActor;


class NxFrameListener: public ExampleFrameListener
{
private:

protected:

public:
NxFrameListener(RenderWindow* pWin, Camera* pCam)
: ExampleFrameListener(pWin, pCam)
{
}


bool frameEnded(const Ogre::FrameEvent &evt)
{
gCameraActor->setGlobalPosition(mCamera->getPosition());
gCameraActor->setGlobalOrientation(mCamera->getOrientation());

return ExampleFrameListener::frameEnded(evt);
}
};


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

~NxOgreApp()
{
destroyNxWorld();
}

protected:
NxOgre::World* mWorld;
NxOgre::Scene* mScene;


void createNxWorld(void)
{
NxOgre::PhysXParams physXparams;
physXparams.setToDefault();
physXparams.mTimeController = NxOgre::PhysXParams::TC_OGRE;
physXparams.mUseLog = true;

mWorld = new NxOgre::World(physXparams);
mWorld->getPhysXDriver()->createDebuggerConnection();
}


void createNxScene(void)
{
NxOgre::SceneParams sceneParams;
sceneParams.setToDefault();
sceneParams.mRenderer = NxOgre::SceneParams::RN_OGRE;
sceneParams.mGravity = NxVec3(0, -9.8, 0);
sceneParams.mFloor = true;

mScene = mWorld->createScene("Main Scene", sceneParams);

NxOgre::ActorParams actorParams;
actorParams.setToDefault();
actorParams.mMass = 10.0f;

NxOgre::Body* body =
mScene->createBody
(
"head123456; ogrehead.mesh",
new NxOgre::Sphere(30),
Vector3(0, 0, 0),
actorParams
);
}


void createNxCameraActor(void)
{
NxOgre::ActorParams actorParams;
actorParams.setToDefault();
actorParams.mMass = 10.0f;
actorParams.mLinearDamping = 10.0f;
actorParams.mAngularDamping = 10.0f;
actorParams.mBodyFlags |= NX_BF_DISABLE_GRAVITY;

NxOgre::Pose cameraPose(mCamera->getPosition(), mCamera->getOrientation());
gCameraActor =
mScene->createActor
(
"NxCamera Actor",
new NxOgre::Sphere(10.0f),
cameraPose,
actorParams
);

}


void destroyNxWorld(void)
{
if (NULL != mWorld)
{
mWorld->getPhysXDriver()->destroyDebuggerConnection();
delete mWorld;
}
}


void createCamera(void)
{
ExampleApplication::createCamera();

mCamera->setNearClipDistance(1);
mCamera->setFarClipDistance(4000);
mCamera->setPosition(0, 100, -100);
mCamera->lookAt(0, 0, 0);
}


// Scene creation
void createScene(void)
{
Ogre::Light* l = mSceneMgr->createLight("Main Light");
l->setDirection(0, -1, 0);

// Create PhysX stuff.
createNxWorld();
createNxScene();
createNxCameraActor();
}

void createFrameListener()
{
mFrameListener = new NxFrameListener(mWindow, mCamera);
mRoot->addFrameListener(mFrameListener);
}

};




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

#ifdef __cplusplus
extern "C" {
#endif

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

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

return 0;
}

#ifdef __cplusplus
}
#endif

betajaen

09-07-2008 11:53:17

Have you tried using a different mesh? Such as cube.1m.mesh?

Rasengan

09-07-2008 12:05:57

just now...same result.

betajaen

09-07-2008 13:04:05

void createNxScene(void)
{

mScene = mWorld->createScene("Main Scene", "renderer: ogre, controller: accumulator, gravity: yes");

NxOgre::ActorParams actorParams;
actorParams.setToDefault();
actorParams.mMass = 10.0f;

NxOgre::NodeRenderableParams nrparams;
nrparams.setToDefault();
nrparams.mIdentifier = "ogre-head-node";
nrparams.mIdentifierUsage = NxOgre::NodeRenderableParams::IU_Create;
nrparams.mGraphicsModel = "ogrehead.mesh";
nrparams.mGraphicsModelType = NxOgre::NodeRenderableParams::GMU_Resource;

NxOgre::Body* body =
mScene->createBody
(
"ogre-head-body",
new NxOgre::Sphere(30),
Vector3(0, 0, 0),
nrparams,
actorParams
);
}

Rasengan

09-07-2008 14:20:00

same result as before: application don't crash, actors visible in remote debugger, nothing rendered in app.

This is strange because it works with my home PC and not with office PC.
Only major difference is the graphic card.

Rasengan

10-07-2008 17:29:18

I've installed Ogre 1.4.9, both SRC and SDK.
Cleaning env vars, libs path (VC 2005...), and rebuild NxOgre 1.0 '21.

Finally, the mesh is rendered on screen!