• Advertisement
Sign in to follow this  

Adding RigidBody to Physics Engine

This topic is 2056 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

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:

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();
}

Share this post


Link to post
Share on other sites
Advertisement

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.
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
The problem occur when the following line get executed:
hkpSphereShape *sphereShape = new hkpSphereShape(100.0f);

Share this post


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

  • Advertisement