Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


[ODE] Access Violation at dCollide when using TriMeshes


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 sjaakiejj   Members   -  Reputation: 130

Like
0Likes
Like

Posted 01 April 2012 - 03:01 PM

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[i].surface.mode = dContactBounce;
        contact[i].surface.mu = dInfinity;
        contact[i].surface.mu2 = 0;
        contact[i].surface.bounce = 0.01;
        contact[i].surface.bounce_vel = 0.5;
        contact[i].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

Sponsor:

#2 Ashaman73   Crossbones+   -  Reputation: 7876

Like
0Likes
Like

Posted 03 April 2012 - 03:22 AM

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.

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.

#3 sjaakiejj   Members   -  Reputation: 130

Like
0Likes
Like

Posted 03 April 2012 - 08:56 AM


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.

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.


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

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS