mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 08:04:01 +02:00
remove dangling shape pointers from PhysicsSimulation
This commit is contained in:
parent
4d0474483d
commit
a1fccdb177
3 changed files with 9 additions and 1 deletions
|
@ -65,6 +65,9 @@ void PhysicsEntity::setEnableShapes(bool enable) {
|
|||
}
|
||||
|
||||
void PhysicsEntity::clearShapes() {
|
||||
if (_simulation) {
|
||||
_simulation->removeShapes(this);
|
||||
}
|
||||
for (int i = 0; i < _shapes.size(); ++i) {
|
||||
delete _shapes[i];
|
||||
}
|
||||
|
|
|
@ -70,6 +70,7 @@ void PhysicsSimulation::removeEntity(PhysicsEntity* entity) {
|
|||
if (!entity || !entity->_simulation || !(entity->_simulation == this)) {
|
||||
return;
|
||||
}
|
||||
removeShapes(entity);
|
||||
int numEntities = _entities.size();
|
||||
for (int i = 0; i < numEntities; ++i) {
|
||||
if (entity == _entities.at(i)) {
|
||||
|
@ -86,7 +87,10 @@ void PhysicsSimulation::removeEntity(PhysicsEntity* entity) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
// remove corresponding contacts
|
||||
}
|
||||
|
||||
void PhysicsSimulation::removeShapes(const PhysicsEntity* entity) {
|
||||
// remove data structures with pointers to entity's shapes
|
||||
QMap<quint64, ContactPoint>::iterator itr = _contacts.begin();
|
||||
while (itr != _contacts.end()) {
|
||||
if (entity == itr.value().getShapeA()->getEntity() || entity == itr.value().getShapeB()->getEntity()) {
|
||||
|
|
|
@ -32,6 +32,7 @@ public:
|
|||
bool addEntity(PhysicsEntity* entity);
|
||||
|
||||
void removeEntity(PhysicsEntity* entity);
|
||||
void removeShapes(const PhysicsEntity* entity);
|
||||
|
||||
/// \return true if doll was added to or is already in the list
|
||||
bool addRagdoll(Ragdoll* doll);
|
||||
|
|
Loading…
Reference in a new issue