Sign in to follow this  
Medo Mex

Adding RigidBody to Physics Engine

Recommended Posts

Medo Mex    891
I am trying to use the following code to add RigidBody to Havok Physics, but I am getting 'Access violation reading location' error:
First-chance exception at 0x016141b6 in DirectX Level.exe: 0xC0000005: Access violation reading location 0x0000002c.

File: hkThreadLocalData.h

I need someone to update the following code to make it work:
[CODE]
static void HK_CALL errorReport(const char* msg, void* userContext)
{
using namespace std;
printf("%s", msg);
}

HavokManager::HavokManager()
{
hkMallocAllocator baseMalloc;
// Need to have memory allocated for the solver. Allocate 1mb for it.
memoryRouter = hkMemoryInitUtil::initDefault(
&baseMalloc, hkMemorySystem::FrameInfo(1024 * 1024) );
hkBaseSystem::init( memoryRouter, errorReport );
{
// object for custom information about the world
hkpWorldCinfo info;

// e.g. set manually the gravity (try to tune this parameter!)
info.m_gravity.set( 0,-9.8f,0);

// use default information (try to use our "info" object)
m_world = new hkpWorld( hkpWorldCinfo() );

// Register all collision agents (before adding entities, try doing the opposite!)
hkpAgentRegisterUtil::registerAllAgents( m_world->getCollisionDispatcher() );
}
}

void HavokManager::AddEntity(ENTITY *entity)
{
D3DXVECTOR4 dimensions(50.0f, 50.0f, 50.0f, 0.0f);
D3DXVECTOR4 pos(0.0f, 0.0f, 0.0f, 0.0f);

hkVector4 hDim(dimensions.x/2,
dimensions.y/2,
dimensions.z/2,
dimensions.w);

hkVector4 hPos(pos.x,
pos.y,
pos.z,
pos.w);

hkpConvexShape* shape = new hkpBoxShape(hDim, 0);

hkpRigidBodyCinfo rigidBodyInfo;

rigidBodyInfo.m_motionType = hkpMotion::MOTION_FIXED;
rigidBodyInfo.m_shape = shape;
rigidBodyInfo.m_position = hPos;
rigidBodyInfo.m_allowedPenetrationDepth = 0;

hkpRigidBody* rigidBody = new hkpRigidBody(rigidBodyInfo);

m_world->lock();
m_world->addEntity(rigidBody);

rigidBody->removeReference();
shape->removeReference();

m_world->unlock();
}[/CODE]

Share this post


Link to post
Share on other sites
Hodgman    51334
[quote name='Medo3337' timestamp='1341408686' post='4955617']
I am trying to use the following code to add RigidBody to Havok Physics, but I am getting 'Access violation reading location' error:
First-chance exception at 0x016141b6 in DirectX Level.exe: 0xC0000005: Access violation reading location 0x0000002c.
[/quote]This usually means that you've tried to use a NULL pointer, which is a general C++ coding error unrelated to any API. Your debugger should stop on the specific line of code which was using this pointer, at which point, you can inspect the values of your variables to see which pointer is invalid. Which line does it stop on? Edited by Hodgman

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this