Browse Source

Added guardiang to BulletTriangleMeshShape CTOR which asserts that meshes have at least one triangle.

enn0x 14 years ago
parent
commit
da7458efce
2 changed files with 16 additions and 28 deletions
  1. 4 28
      panda/src/bullet/bulletDebugNode.cxx
  2. 12 0
      panda/src/bullet/bulletTriangleMeshShape.cxx

+ 4 - 28
panda/src/bullet/bulletDebugNode.cxx

@@ -170,6 +170,8 @@ draw_mask_changed() {
     if (_verbose) {
     if (_verbose) {
       _drawer.setDebugMode(DebugDraw::DBG_DrawWireframe |
       _drawer.setDebugMode(DebugDraw::DBG_DrawWireframe |
                            DebugDraw::DBG_DrawAabb |
                            DebugDraw::DBG_DrawAabb |
+                           DebugDraw::DBG_DrawText |
+                           DebugDraw::DBG_DrawFeaturesText |
                            DebugDraw::DBG_DrawContactPoints |
                            DebugDraw::DBG_DrawContactPoints |
                            DebugDraw::DBG_DrawConstraints |
                            DebugDraw::DBG_DrawConstraints |
                            DebugDraw::DBG_DrawConstraintLimits);
                            DebugDraw::DBG_DrawConstraintLimits);
@@ -183,23 +185,6 @@ draw_mask_changed() {
   } 
   } 
 }
 }
 
 
-/*
-DBG_DrawWireframe
-DBG_DrawAabb
-DBG_DrawText
-DBG_DrawFeaturesText
-DBG_DrawContactPoints
-DBG_DrawConstraints
-DBG_DrawConstraintLimits
-DBG_NoDeactivation
-DBG_NoHelpText
-DBG_EnableSatComparison
-DBG_DisableBulletLCP
-DBG_ProfileTimings
-DBG_EnableCCD
-DBG_FastWireframe
-*/
-
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: BulletDebugNode::post_step
 //     Function: BulletDebugNode::post_step
 //       Access: Private
 //       Access: Private
@@ -261,17 +246,8 @@ post_step(btDynamicsWorld *world) {
   _drawer._triangles.clear();
   _drawer._triangles.clear();
 
 
   // Force recompute of bounds
   // Force recompute of bounds
-  int num_geoms = this->get_num_geoms();
-  for (int i = 0; i < num_geoms; i++) {
-    const Geom *geom = this->get_geom(i);
-    geom->mark_bounds_stale();
-  }
-
-  this->mark_bounds_stale();
-
-  // Alternate way, probably a little bit slower
-  //NodePath np = NodePath::any_path(this);
-  //np.force_recompute_bounds();
+  NodePath np = NodePath::any_path(this);
+  np.force_recompute_bounds();
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////

+ 12 - 0
panda/src/bullet/bulletTriangleMeshShape.cxx

@@ -30,6 +30,18 @@ TypeHandle BulletTriangleMeshShape::_type_handle;
 BulletTriangleMeshShape::
 BulletTriangleMeshShape::
 BulletTriangleMeshShape(BulletTriangleMesh *mesh, bool dynamic, bool compress, bool bvh) {
 BulletTriangleMeshShape(BulletTriangleMesh *mesh, bool dynamic, bool compress, bool bvh) {
 
 
+  // Assert that mesh is not NULL
+  if (!mesh) {
+    bullet_cat.warning() << "mesh is NULL! creating new mesh." << endl;
+    mesh = new BulletTriangleMesh();
+  }
+
+  // Assert that mesh has at least one triangle
+  if (mesh->get_num_triangles() == 0) {
+    bullet_cat.warning() << "mesh has zero triangles! adding degenerated triangle." << endl;
+    mesh->add_triangle(LPoint3f::zero(), LPoint3f::zero(), LPoint3f::zero());
+  }
+
   // Retain a pointer to the mesh, to prevent it from being deleted
   // Retain a pointer to the mesh, to prevent it from being deleted
   _mesh = mesh;
   _mesh = mesh;