Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10415


Ignore:
Timestamp:
May 3, 2015, 12:19:49 PM (10 years ago)
Author:
landauf
Message:

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.

Location:
code/branches/core7/src/orxonox
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core7/src/orxonox/Scene.cc

    r10347 r10415  
    6767        this->debugDrawer_ = NULL;
    6868        this->soundReferenceDistance_ = 20.0;
     69        this->bIsUpdatingPhysics_ = false;
    6970
    7071        if (GameMode::showsGraphics())
     
    266267            // Note: 60 means that Bullet will do physics correctly down to 1 frames per seconds.
    267268            //       Under that mark, the simulation will "loose time" and get unusable.
    268             physicalWorld_->stepSimulation(dt, 60);
     269            this->bIsUpdatingPhysics_ = true;
     270            this->physicalWorld_->stepSimulation(dt, 60);
     271            this->bIsUpdatingPhysics_ = false;
    269272
    270273            if (this->bDebugDrawPhysics_)
    271                 physicalWorld_->debugDrawWorld();
     274                this->physicalWorld_->debugDrawWorld();
    272275        }
    273276    }
  • code/branches/core7/src/orxonox/Scene.h

    r10196 r10415  
    110110
    111111        public:
    112             inline bool hasPhysics()
     112            inline bool hasPhysics() const
    113113                { return this->physicalWorld_ != 0; }
    114114            void setPhysicalWorld(bool wantsPhysics);
     
    128128            void addPhysicalObject(WorldEntity* object);
    129129            void removePhysicalObject(WorldEntity* object);
     130
     131            inline bool isUpdatingPhysics() const
     132                { return this->bIsUpdatingPhysics_; }
    130133
    131134            void setDebugDrawPhysics(bool bDraw, bool bFill, float fillAlpha);
     
    163166            BulletDebugDrawer*                   debugDrawer_;
    164167            bool                                 bDebugDrawPhysics_;
     168            bool                                 bIsUpdatingPhysics_;
    165169    };
    166170}
  • code/branches/core7/src/orxonox/collisionshapes/CollisionShape.cc

    r10362 r10415  
    4141#include "CompoundCollisionShape.h"
    4242#include "WorldEntityCollisionShape.h"
     43#include "Scene.h"
    4344
    4445namespace orxonox
     
    7475    {
    7576        // Detach from parent CompoundCollisionShape.
    76         if (this->isInitialized() && this->parent_)
    77             this->parent_->detach(this);
     77        if (this->isInitialized())
     78        {
     79            if (this->getScene() && this->getScene()->isUpdatingPhysics())
     80                orxout(internal_error) << "Don't destroy collision shapes while the physics is updated! This will lead to crashes" << endl;
     81
     82            if (this->parent_)
     83                this->parent_->detach(this);
     84        }
    7885    }
    7986
Note: See TracChangeset for help on using the changeset viewer.