[ODE] Access Violation at dCollide when using TriMeshes

Started by
1 comment, last by sjaakiejj 12 years ago
Hey guys,

I've been scratching my head at this for a while now, and Google hasn't been my friend for this particular issue. This is my first time using ODE after somebody recommended it to me, and it seems to be a fairly nice and straightforward library to use. However, I'm having some trouble with the use of TriMeshes. Since I want to have terrain collision detection, I decided to use ODE's built-in TriMesh to represent the terrain. Of course, I start off with a simple 2-triangle square representing my "Terrain". I do that with the following code:


void PhysicsManager::createTriMeshBB(Model* model)
{
const int vCount = 4;
float vertices[vCount * 3] = {
0,0,0,
20*30,0,0,
20*30,0,20*30,
0,0,20*30
};
dTriIndex indices[6] = {
0,1,2,
0,2,3
};

dTriMeshDataID dataID;
dGeomID geomID;

dataID = dGeomTriMeshDataCreate();
dGeomTriMeshDataBuildSingle(dataID, vertices, sizeof(float)*3, vCount, indices, 6, sizeof(dTriIndex)*3);
//dGeomTriMeshDataBuildSimple(dataID, vertices, 4, tmpCreateIndices(), 6);

geomID = dCreateTriMesh(mSpace, dataID, 0, 0, 0);

dGeomSetPosition(geomID,0,0,0);
dGeomSetBody(geomID, 0);

model->setGeometryID(geomID);
}


After having done this, I specify a callback function - say "tmpCallback" as below:


void PhysicsManager::tmpCallback(void * d, dGeomID id1, dGeomID id2)
{


int i;

// Get the dynamics bodies
dBodyID b1 = dGeomGetBody(id1);
dBodyID b2 = dGeomGetBody(id2);

std::cout << "Callback" << std::endl;
// Holds the contact joints - Need to read up on this
dContact contact[32];
dContactGeom ptr;

for (i = 0; i < 32; i++)
{
contact.surface.mode = dContactBounce;
contact.surface.mu = dInfinity;
contact.surface.mu2 = 0;
contact.surface.bounce = 0.01;
contact.surface.bounce_vel = 0.5;
contact.surface.soft_cfm = 0.01;
}
int numc = dCollide(id1, id2, 1, &contact[0].geom, sizeof(dContact));
if (numc > 0)
{
for (i = 0; i < numc; i++)
{
dJointID c = dJointCreateContact(PhysicsManager::get()->getWorld(), PhysicsManager::get()->getContactGroup(), contact + i);
dJointAttach(c, b1, b2);
}
}
}


This callback function works perfectly when doing plane to sphere collision detection. When the TriMesh is involved however, the program crashes at "dCollide(id1,id2, 1, &contact[0].geom, sizeof(dContact))", throwing an unhandled Access Violation from inside the standard libraries. I'm at a loss at what's causing the problem, and I've tried everything I could think of to solve it.

If you want to slap me in the face and tell me I shouldn't be using ODE, that's fine as well - please do give your own recommendations however :)

Thanks in advance
Advertisement

dGeomTriMeshDataBuildSingle(dataID, vertices, sizeof(float)*3, vCount, indices, 6, sizeof(dTriIndex)*3);

From the doc over here:

Applies to all the dGeomTriMeshDataBuild single and double versions. (From http://ode.org/ode-latest-userguide.html#sec_10_7_6) Used for filling a dTriMeshData object with data. No data is copied here, so the pointers passed into this function must remain valid.
[/quote]
So, you fill your data with temporary data which will be gone once you leave the createTriMeshBB method. Here's a fast hack, please do this not at home:

static float vertices[vCount * 3] = {
0,0,0,
20*30,0,0,
20*30,0,20*30,
0,0,20*30
};
static dTriIndex indices[6] = {
0,1,2,
0,2,3
};


When this work, try to use some proper memory management to handle your mesh data.

[quote name='sjaakiejj' timestamp='1333314094' post='4927275']
dGeomTriMeshDataBuildSingle(dataID, vertices, sizeof(float)*3, vCount, indices, 6, sizeof(dTriIndex)*3);

From the doc over here:

Applies to all the dGeomTriMeshDataBuild single and double versions. (From http://ode.org/ode-l...html#sec_10_7_6) Used for filling a dTriMeshData object with data. No data is copied here, so the pointers passed into this function must remain valid.
[/quote]
So, you fill your data with temporary data which will be gone once you leave the createTriMeshBB method. Here's a fast hack, please do this not at home:

static float vertices[vCount * 3] = {
0,0,0,
20*30,0,0,
20*30,0,20*30,
0,0,20*30
};
static dTriIndex indices[6] = {
0,1,2,
0,2,3
};


When this work, try to use some proper memory management to handle your mesh data.
[/quote]

How could I have missed that line? Besides, it's pretty logical... Thanks a lot, I'll go try it immediately smile.png

Edit: It works, I had an additional issue afterwards which was that my object was just falling through the plane, but turned out the plane was upside down.

This topic is closed to new replies.

Advertisement