[ODE] sphere-mesh and box-mesh crash

Adam D. Moss adam at gimp.org
Sat Jun 25 14:01:15 MST 2005


Patrick Enoch wrote:
> I experienced crashes. The container with the touched primitives was  
> supposedly filled with a lot of
> triangles. when checking the triangles, I saw there were indices like  
> "0xC0BA1234" and so on... this
> certainly causing to crash "FetchTriangle" in the following code...
> when testing for the status I saw that the status said "no  collisions", 
> thus the indices are bogus.

If Collider.GetNbTouchedPrimitives()==0 then AFAICS we never execute
the FetchTriangle path, so is GetNbTouchedPrimitives()'s return actually
bogus if we didn't collide?

In either case, Collider.GetContactStatus() looks like a cheap function
so it doesn't hurt to be protective, but it'd be better if we were
sure we weren't wallpapering over a different bug.  We might well just
be using OPCODE wrongly (i.e. GetNbTouchedPrimitives only works if
there was a collision).

Does this patch look okay?  It tests okay.  I'll apply it to the trunk
shortly, if so.

--adam
-------------- next part --------------
Index: ode/src/collision_trimesh_box.cpp
===================================================================
--- ode/src/collision_trimesh_box.cpp	(revision 4638)
+++ ode/src/collision_trimesh_box.cpp	(working copy)
@@ -1203,6 +1203,11 @@
 		Collider.Collide(dxTriMesh::defaultBoxCache, Box, TriMesh->Data->BVTree, null, 
 						 &MakeMatrix(vPosMesh, mRotMesh, amatrix));	
 	}
+
+  if (!Collider.GetContactStatus()) {
+     /* no collision occurred */
+     return 0;
+  }
 	    
   // Retrieve data
   int TriCount = Collider.GetNbTouchedPrimitives();
Index: ode/src/collision_trimesh_ccylinder.cpp
===================================================================
--- ode/src/collision_trimesh_ccylinder.cpp	(revision 4638)
+++ ode/src/collision_trimesh_ccylinder.cpp	(working copy)
@@ -958,6 +958,11 @@
 		 Collider.Collide(dxTriMesh::defaultBoxCache, obbCCylinder, TriMesh->Data->BVTree, null,&MeshMatrix);
 	 }
 
+         if (!Collider.GetContactStatus()) {
+            /* no collision occurred */
+            return 0;
+         }
+
 	 // Retrieve data
 	 int TriCount = Collider.GetNbTouchedPrimitives();
 	 const int* Triangles = (const int*)Collider.GetTouchedPrimitives();
Index: ode/src/collision_trimesh_sphere.cpp
===================================================================
--- ode/src/collision_trimesh_sphere.cpp	(revision 4638)
+++ ode/src/collision_trimesh_sphere.cpp	(working copy)
@@ -305,6 +305,11 @@
 						 &MakeMatrix(TLPosition, TLRotation, amatrix));
  	}
 
+        if (!Collider.GetContactStatus()) {
+            /* no collision occurred */
+            return 0;
+        }
+
 	// get results
 	int TriCount = Collider.GetNbTouchedPrimitives();
 	const int* Triangles = (const int*)Collider.GetTouchedPrimitives();


More information about the ODE mailing list