btBvhTriangleMeshShape Unhandled exception/Access violation

Post Reply
anfractu0us
Posts: 3
Joined: Fri Nov 30, 2012 10:23 pm

btBvhTriangleMeshShape Unhandled exception/Access violation

Post by anfractu0us »

Hello all! I've recently integrated Bullet 2.81 into my codebase, and it's quite a wonderful thing! :) After screwing around with the examples and doing some research, I looked into creating physics meshes so I could use my level geometry as a static element. I originally used the addTriangle method which worked, until I realized that my mesh uses indices and as such it resulted in a physics mesh that had holes in it, allowing my primitives to just roll through/fall through. I tried a couple different things and read around on the forums, and ended up with this in an attempt to utilize my indices:

Code: Select all

btTriangleIndexVertexArray *tri_mesh = new btTriangleIndexVertexArray();
	
btIndexedMesh i_mesh;
i_mesh.m_numTriangles        = s_phys.get_phys_inds().size();
i_mesh.m_triangleIndexBase   = (const unsigned char *)s_phys.get_phys_inds()[0];
i_mesh.m_triangleIndexStride = sizeof(face_ind);
i_mesh.m_numVertices         = s_phys.get_phys_verts().size();
i_mesh.m_vertexBase          = (const unsigned char *)&s_phys.get_phys_verts()[0]->getX();
i_mesh.m_vertexStride        = sizeof(btVector3);
i_mesh.m_indexType	     = PHY_INTEGER;
i_mesh.m_vertexType	     = PHY_FLOAT;
tri_mesh->addIndexedMesh( i_mesh, PHY_INTEGER );
	

btBvhTriangleMeshShape *cur_scene; 
	
cur_scene = new btBvhTriangleMeshShape(tri_mesh,true);
s_phys.get_phys_inds() returns the vector of face indices, a struct as such:

Code: Select all

struct face_ind
{
	GLuint indx1;
	GLuint indx2;
	GLuint indx3;
};
s_phys.get_phys_verts() is the converted form from my mesh vert struct (which allows x, y, z, u and v) and only has the x,y,z data as per a btVector3. Because my face_ind struct is three integers I don't multiply it by 3, as it returns 12 as is. I'm not quite sure why, but it throws an access violation error when constructing the meshshape, specifically in the striding mesh interface.

Code: Select all

>	!btStridingMeshInterface::InternalProcessAllTriangles()  + 0x4c8 bytes
I'm not sure if perhaps something is wrong with my data or if I'm doing something wrong, but I've tried breaking down my face_ind struct into an unsigned int array; the same thing happens. The pointers are also valid for both VertexBase and IndexBase for the btIndexedMesh. Thanks for taking a look! If you need any more code or whatnot, let me know - I'll gladly post it.
Post Reply