Gimpact Crash

0xc0deface
Posts: 5
Joined: Mon Aug 27, 2012 4:55 am

Gimpact Crash

Post by 0xc0deface »

Hi.

I'm posting to report a crash that can occur in btGImpactShape.h when using large meshes that cause the signed indices to become negative. The solution is to simply use unsigned indicies. See the following diff:

Code: Select all

Index: btGImpactShape.h
===================================================================
--- btGImpactShape.h	(revision 5646)
+++ btGImpactShape.h	(revision 5647)
@@ -636,25 +636,25 @@
 			return (int )numverts;
 		}
 
-		SIMD_FORCE_INLINE void get_indices(int face_index,int &i0,int &i1,int &i2) const
+		SIMD_FORCE_INLINE void get_indices(int face_index,unsigned int &i0,unsigned int &i1,unsigned int &i2) const
 		{
 			if(indicestype == PHY_SHORT)
 			{
-				short * s_indices = (short *)(indexbase + face_index*indexstride);
+				unsigned short* s_indices = (unsigned short *)(indexbase + face_index * indexstride);
 				i0 = s_indices[0];
 				i1 = s_indices[1];
 				i2 = s_indices[2];
 			}
 			else
 			{
-				int * i_indices = (int *)(indexbase + face_index*indexstride);
+				unsigned int * i_indices = (unsigned int *)(indexbase + face_index*indexstride);
 				i0 = i_indices[0];
 				i1 = i_indices[1];
 				i2 = i_indices[2];
 			}
 		}
 
-		SIMD_FORCE_INLINE void get_vertex(int vertex_index, btVector3 & vertex) const
+		SIMD_FORCE_INLINE void get_vertex(unsigned int vertex_index, btVector3 & vertex) const
 		{
 			if(type == PHY_DOUBLE)
 			{
@@ -683,7 +683,7 @@
 
 		virtual void get_primitive_triangle(int prim_index,btPrimitiveTriangle & triangle) const
 		{
-			int indices[3];
+			unsigned int indices[3];
 			get_indices(prim_index,indices[0],indices[1],indices[2]);
 			get_vertex(indices[0],triangle.m_vertices[0]);
 			get_vertex(indices[1],triangle.m_vertices[1]);
@@ -693,7 +693,7 @@
 
 		SIMD_FORCE_INLINE void get_bullet_triangle(int prim_index,btTriangleShapeEx & triangle) const
 		{
-			int indices[3];
+			unsigned int indices[3];
 			get_indices(prim_index,indices[0],indices[1],indices[2]);
 			get_vertex(indices[0],triangle.m_vertices1[0]);
 			get_vertex(indices[1],triangle.m_vertices1[1]);
Thanks!
0xc0deface
Posts: 5
Joined: Mon Aug 27, 2012 4:55 am

Re: Gimpact Crash

Post by 0xc0deface »

So was this change implimented? its very simple and fixes crash.

Thanks!
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Gimpact Crash

Post by Erwin Coumans »

Can you please report bug fixes in the issue tracker at https://code.google.com/p/bullet/issues/list
In this forum they will get lost.

Thanks for your help!
Erwin
0xc0deface
Posts: 5
Joined: Mon Aug 27, 2012 4:55 am

Re: Gimpact Crash

Post by 0xc0deface »

Ah cool. I wasn't sure where to post issues and fixes. Thanks for this. I'll be sure to submit future fixes and patches there. This one has been submit as issues 663 :).