Crash on collision creation, help please!

bowringjb

07-11-2006 13:41:06

hi can anyone help me please, when I compile my program it crashes upon running, exiting with the following error:

Unhandled exception at 0x0058c9f0 in ogredemo4.exe: 0xC0000005: Access violation reading location 0x582f3a69.

and refers me to this point in the renderprimitives.cpp:

m_col = NewtonCreateBox( m_world->getNewtonWorld(), (float)size.x, (float)size.y, (float)size.z, &matrix[0] );

does anyone have any suggestions please, following is the bulk of the code:

#include <Ogre.h>
#include <OgreErrorDialog.h>
#include <Newton.h>
#include "windows.h"
#include "myFrameListener.h"
#include "matrix_tools.h"
#include <OgreFrameListener.h>
#include <ogreNewt.h>

#define WIN32_LEAN_AND_MEAN

using namespace Ogre;
using namespace std;

// GLOBALS

SceneNode* box_node;

void setupResources(void)
{
// Load resource paths from config file
ConfigFile cf;
cf.load("E:/XPDocuments/Visual Studio 2005/Projects/ogredemo4/ogredemo4/bin/resources.cfg");

// Go through all sections & settings in the file
ConfigFile::SectionIterator seci = cf.getSectionIterator();

String secName, typeName, archName;
while (seci.hasMoreElements())
{
secName = seci.peekNextKey();
ConfigFile::SettingsMultiMap *settings = seci.getNext();
ConfigFile::SettingsMultiMap::iterator i;
for (i = settings->begin(); i != settings->end(); ++i)
{
typeName = i->first;
archName = i->second;
ResourceGroupManager::getSingleton().addResourceLocation(
archName, typeName, secName);
}
}
Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
}

MyFrameListener::MyFrameListener(InputReader* ir) : mInputReader(ir)
{

}

bool MyFrameListener::frameStarted(const FrameEvent& evt)
{
//--MAIN GAME LOOP

mInputReader->capture();
if (mInputReader->isKeyDown(KC_ESCAPE))
{
return false;
}
return true;
}






INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
{
try
{
//--------- ENTRY POINT --------

// Initialisation of Root and SceneManager
Root* mRoot = new Root("E:/XPDocuments/Programming/ogre/installation/OgreSDK/bin/release/plugins.cfg","../ogre.cfg","ogre.log");

// Setup screen configuration
//if(!mRoot->restoreConfig())
//{
if(!mRoot->showConfigDialog())
{
return 1;
}
//}
// create renderwindow
RenderWindow* mWindow = mRoot->initialise(true,"Hello");

// create scemenemanager
SceneManager* mSceneManager = mRoot->createSceneManager(ST_GENERIC,"sceneManager");

// create camera
Camera* mCamera = mSceneManager->createCamera("Camera");
mCamera->setPosition(Vector3(50.0f,50.0f,50.0f));
mCamera->lookAt(Vector3(0.0f,0.0f,0.0f));
mCamera->setNearClipDistance(5.0f);
mCamera->setFarClipDistance(5000.0f);
mCamera->setProjectionType(PT_PERSPECTIVE);
mCamera->setFOVy(Radian(Angle(36)));

// add viewport and bind camera
Viewport* mViewport = mWindow->addViewport(mCamera);
mViewport->setBackgroundColour(ColourValue(0.0f,0.0f,0.0f));

// set camera aspect ratio
mCamera->setAspectRatio(Real(mViewport->getActualWidth())/Real(mViewport->getActualHeight()));

// create input
InputReader* mInputReader = PlatformManager::getSingleton().createInputReader();
mInputReader->initialise(mWindow,true,false);

// register frame listener
MyFrameListener* mFrameLst = new MyFrameListener(mInputReader);
mRoot->addFrameListener(mFrameLst);

//setup resource paths
setupResources();

// Load box mesh
Entity* box_d = mSceneManager->createEntity( "dynamic_box", "texbox.mesh" );
box_node = mSceneManager->getRootSceneNode()->createChildSceneNode("dynamic_box_node");
box_node->attachObject(box_d);
box_node->setPosition(Vector3(0,10,0));

// Load floor mesh
Entity* floor = mSceneManager->createEntity( "floor_static", "floor.mesh" );
SceneNode* floor_node = mSceneManager->getRootSceneNode()->createChildSceneNode("static_floor_node");
floor_node->attachObject(floor);

// add light
Light* light = mSceneManager->createLight( "Light1" );
light->setType( Light::LT_POINT );
light->setPosition( Vector3(0, 150, 250) );
light->setDiffuseColour( 1.0, 1.0, 1.0 );
light->setSpecularColour( 1.0, 1.0, 1.0 );

// initialise physics
OgreNewt::World* mWorld;
// collisions
Ogre::Vector3 size(5,5,5);
OgreNewt::Collision* boxcol = new OgreNewt::CollisionPrimitives::Box(mWorld, size);
OgreNewt::Body* boxbody = new OgreNewt::Body( mWorld, boxcol );
boxbody->attachToNode( box_node );
//boxbody->setPositionOrientation( Ogre::Vector3(0,-5,0), Ogre::Quaternion::IDENTITY );
delete boxcol;
//OgreNewt::Collision* floorcol = new OgreNewt::CollisionPrimitives::Box( mWorld, Vector3(24.0f,1.0f,24.0f));

// Render
mRoot->startRendering();

// cleanup
delete mRoot;

//--------- End of Entry Point -
}
catch (Exception& e)
{
ErrorDialog* dlg = PlatformManager::getSingleton().createErrorDialog();
dlg->display(e.getFullDescription());
delete dlg;
return 1;
}
return 0;
}

bowringjb

07-11-2006 13:41:58

oh and also I am compiling with VC8, if thats any help, thanks

abecam

08-11-2006 12:47:24

It seems to me that you forgot to create your world ( mWorld = new OgreNewt::World(); ). That might explain the "memory access" crash (because m_world->getNewtonWorld() cannot work). So you should change this part:

// initialise physics
OgreNewt::World* mWorld;
// collisions
Ogre::Vector3 size(5,5,5);
OgreNewt::Collision* boxcol = new OgreNewt::CollisionPrimitives::Box(mWorld, size);


just by adding the needed creation:

// initialise physics
OgreNewt::World* mWorld = new OgreNewt::World();;
// collisions
Ogre::Vector3 size(5,5,5);
OgreNewt::Collision* boxcol = new OgreNewt::CollisionPrimitives::Box(mWorld, size);