mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 04:37:59 +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() {
|
void PhysicsEntity::clearShapes() {
|
||||||
|
if (_simulation) {
|
||||||
|
_simulation->removeShapes(this);
|
||||||
|
}
|
||||||
for (int i = 0; i < _shapes.size(); ++i) {
|
for (int i = 0; i < _shapes.size(); ++i) {
|
||||||
delete _shapes[i];
|
delete _shapes[i];
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,7 @@ void PhysicsSimulation::removeEntity(PhysicsEntity* entity) {
|
||||||
if (!entity || !entity->_simulation || !(entity->_simulation == this)) {
|
if (!entity || !entity->_simulation || !(entity->_simulation == this)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
removeShapes(entity);
|
||||||
int numEntities = _entities.size();
|
int numEntities = _entities.size();
|
||||||
for (int i = 0; i < numEntities; ++i) {
|
for (int i = 0; i < numEntities; ++i) {
|
||||||
if (entity == _entities.at(i)) {
|
if (entity == _entities.at(i)) {
|
||||||
|
@ -86,7 +87,10 @@ void PhysicsSimulation::removeEntity(PhysicsEntity* entity) {
|
||||||
break;
|
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();
|
QMap<quint64, ContactPoint>::iterator itr = _contacts.begin();
|
||||||
while (itr != _contacts.end()) {
|
while (itr != _contacts.end()) {
|
||||||
if (entity == itr.value().getShapeA()->getEntity() || entity == itr.value().getShapeB()->getEntity()) {
|
if (entity == itr.value().getShapeA()->getEntity() || entity == itr.value().getShapeB()->getEntity()) {
|
||||||
|
|
|
@ -32,6 +32,7 @@ public:
|
||||||
bool addEntity(PhysicsEntity* entity);
|
bool addEntity(PhysicsEntity* entity);
|
||||||
|
|
||||||
void removeEntity(PhysicsEntity* entity);
|
void removeEntity(PhysicsEntity* entity);
|
||||||
|
void removeShapes(const PhysicsEntity* entity);
|
||||||
|
|
||||||
/// \return true if doll was added to or is already in the list
|
/// \return true if doll was added to or is already in the list
|
||||||
bool addRagdoll(Ragdoll* doll);
|
bool addRagdoll(Ragdoll* doll);
|
||||||
|
|
Loading…
Reference in a new issue