[Orxonox-commit 5755] r10415 - in code/branches/core7/src/orxonox: . collisionshapes

landauf at orxonox.net landauf at orxonox.net
Sun May 3 12:19:49 CEST 2015


Author: landauf
Date: 2015-05-03 12:19:49 +0200 (Sun, 03 May 2015)
New Revision: 10415

Modified:
   code/branches/core7/src/orxonox/Scene.cc
   code/branches/core7/src/orxonox/Scene.h
   code/branches/core7/src/orxonox/collisionshapes/CollisionShape.cc
Log:
added check to detect if a collision shape is destroyed during a simulation step of bullet. this usually happens if a collision (or a 'hit') triggers an event which deletes an object. this yields undefined behavior and often leads to crashes.

Modified: code/branches/core7/src/orxonox/Scene.cc
===================================================================
--- code/branches/core7/src/orxonox/Scene.cc	2015-05-03 09:47:50 UTC (rev 10414)
+++ code/branches/core7/src/orxonox/Scene.cc	2015-05-03 10:19:49 UTC (rev 10415)
@@ -66,6 +66,7 @@
         this->bDebugDrawPhysics_ = false;
         this->debugDrawer_ = NULL;
         this->soundReferenceDistance_ = 20.0;
+        this->bIsUpdatingPhysics_ = false;
 
         if (GameMode::showsGraphics())
         {
@@ -265,10 +266,12 @@
 
             // Note: 60 means that Bullet will do physics correctly down to 1 frames per seconds.
             //       Under that mark, the simulation will "loose time" and get unusable.
-            physicalWorld_->stepSimulation(dt, 60);
+            this->bIsUpdatingPhysics_ = true;
+            this->physicalWorld_->stepSimulation(dt, 60);
+            this->bIsUpdatingPhysics_ = false;
 
             if (this->bDebugDrawPhysics_)
-                physicalWorld_->debugDrawWorld();
+                this->physicalWorld_->debugDrawWorld();
         }
     }
 

Modified: code/branches/core7/src/orxonox/Scene.h
===================================================================
--- code/branches/core7/src/orxonox/Scene.h	2015-05-03 09:47:50 UTC (rev 10414)
+++ code/branches/core7/src/orxonox/Scene.h	2015-05-03 10:19:49 UTC (rev 10415)
@@ -109,7 +109,7 @@
         /////////////
 
         public:
-            inline bool hasPhysics()
+            inline bool hasPhysics() const
                 { return this->physicalWorld_ != 0; }
             void setPhysicalWorld(bool wantsPhysics);
 
@@ -128,6 +128,9 @@
             void addPhysicalObject(WorldEntity* object);
             void removePhysicalObject(WorldEntity* object);
 
+            inline bool isUpdatingPhysics() const
+                { return this->bIsUpdatingPhysics_; }
+
             void setDebugDrawPhysics(bool bDraw, bool bFill, float fillAlpha);
 
             static void consoleCommand_debugDrawPhysics(bool bDraw, bool bFill, float fillAlpha);
@@ -162,6 +165,7 @@
 
             BulletDebugDrawer*                   debugDrawer_;
             bool                                 bDebugDrawPhysics_;
+            bool                                 bIsUpdatingPhysics_;
     };
 }
 

Modified: code/branches/core7/src/orxonox/collisionshapes/CollisionShape.cc
===================================================================
--- code/branches/core7/src/orxonox/collisionshapes/CollisionShape.cc	2015-05-03 09:47:50 UTC (rev 10414)
+++ code/branches/core7/src/orxonox/collisionshapes/CollisionShape.cc	2015-05-03 10:19:49 UTC (rev 10415)
@@ -40,6 +40,7 @@
 #include "worldentities/WorldEntity.h"
 #include "CompoundCollisionShape.h"
 #include "WorldEntityCollisionShape.h"
+#include "Scene.h"
 
 namespace orxonox
 {
@@ -73,8 +74,14 @@
     CollisionShape::~CollisionShape()
     {
         // Detach from parent CompoundCollisionShape.
-        if (this->isInitialized() && this->parent_)
-            this->parent_->detach(this);
+        if (this->isInitialized())
+        {
+            if (this->getScene() && this->getScene()->isUpdatingPhysics())
+                orxout(internal_error) << "Don't destroy collision shapes while the physics is updated! This will lead to crashes" << endl;
+
+            if (this->parent_)
+                this->parent_->detach(this);
+        }
     }
 
     void CollisionShape::XMLPort(Element& xmlelement, XMLPort::Mode mode)




More information about the Orxonox-commit mailing list