mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 13:38:02 +02:00
safer delete of AvatarMotionStates
This commit is contained in:
parent
32c367b644
commit
994eed7b83
2 changed files with 22 additions and 33 deletions
|
@ -289,16 +289,6 @@ void AvatarManager::simulateAvatarFades(float deltaTime) {
|
||||||
avatar->removeFromScene(*avatarItr, scene, transaction);
|
avatar->removeFromScene(*avatarItr, scene, transaction);
|
||||||
scene->enqueueTransaction(transaction);
|
scene->enqueueTransaction(transaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete the motionState
|
|
||||||
// TODO: use SharedPointer technology to make this happen automagically
|
|
||||||
assert(!avatar->isInPhysicsSimulation());
|
|
||||||
AvatarMotionStateMap::iterator motionStateItr = _motionStates.find(avatar.get());
|
|
||||||
if (motionStateItr != _motionStates.end()) {
|
|
||||||
delete *motionStateItr;
|
|
||||||
_motionStates.erase(motionStateItr);
|
|
||||||
}
|
|
||||||
|
|
||||||
avatarItr = _avatarsToFade.erase(avatarItr);
|
avatarItr = _avatarsToFade.erase(avatarItr);
|
||||||
} else {
|
} else {
|
||||||
const bool inView = true; // HACK
|
const bool inView = true; // HACK
|
||||||
|
@ -312,24 +302,19 @@ AvatarSharedPointer AvatarManager::newSharedAvatar() {
|
||||||
return std::make_shared<Avatar>(qApp->thread(), std::make_shared<Rig>());
|
return std::make_shared<Avatar>(qApp->thread(), std::make_shared<Rig>());
|
||||||
}
|
}
|
||||||
|
|
||||||
void AvatarManager::removeAvatarFromPhysicsSimulation(Avatar* avatar) {
|
void AvatarManager::handleRemovedAvatar(const AvatarSharedPointer& removedAvatar, KillAvatarReason removalReason) {
|
||||||
assert(avatar);
|
AvatarHashMap::handleRemovedAvatar(removedAvatar, removalReason);
|
||||||
|
|
||||||
|
// remove from physics
|
||||||
|
auto avatar = std::static_pointer_cast<Avatar>(removedAvatar);
|
||||||
avatar->setPhysicsCallback(nullptr);
|
avatar->setPhysicsCallback(nullptr);
|
||||||
AvatarMotionStateMap::iterator itr = _motionStates.find(avatar);
|
AvatarMotionStateMap::iterator itr = _motionStates.find(avatar.get());
|
||||||
if (itr != _motionStates.end()) {
|
if (itr != _motionStates.end()) {
|
||||||
AvatarMotionState* motionState = *itr;
|
AvatarMotionState* motionState = *itr;
|
||||||
_motionStatesToAddToPhysics.remove(motionState);
|
_motionStatesToAddToPhysics.remove(motionState);
|
||||||
_motionStatesToRemoveFromPhysics.push_back(motionState);
|
_motionStatesToRemoveFromPhysics.push_back(motionState);
|
||||||
|
_motionStates.erase(itr);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void AvatarManager::handleRemovedAvatar(const AvatarSharedPointer& removedAvatar, KillAvatarReason removalReason) {
|
|
||||||
AvatarHashMap::handleRemovedAvatar(removedAvatar, removalReason);
|
|
||||||
|
|
||||||
// removedAvatar is a shared pointer to an AvatarData but we need to get to the derived Avatar
|
|
||||||
// class in this context so we can call methods that don't exist at the base class.
|
|
||||||
auto avatar = std::static_pointer_cast<Avatar>(removedAvatar);
|
|
||||||
removeAvatarFromPhysicsSimulation(avatar.get());
|
|
||||||
|
|
||||||
if (removalReason == KillAvatarReason::TheirAvatarEnteredYourBubble) {
|
if (removalReason == KillAvatarReason::TheirAvatarEnteredYourBubble) {
|
||||||
emit DependencyManager::get<UsersScriptingInterface>()->enteredIgnoreRadius();
|
emit DependencyManager::get<UsersScriptingInterface>()->enteredIgnoreRadius();
|
||||||
|
@ -370,14 +355,8 @@ void AvatarManager::clearOtherAvatars() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AvatarManager::deleteAllAvatars() {
|
void AvatarManager::deleteAllAvatars() {
|
||||||
// delete motionStates
|
assert(_motionStates.empty()); // should have called clearOtherAvatars() before getting here
|
||||||
// TODO: use shared_ptr technology to make this work automagically
|
deleteMotionStates();
|
||||||
AvatarMotionStateMap::iterator motionStateItr = _motionStates.begin();
|
|
||||||
while (motionStateItr != _motionStates.end()) {
|
|
||||||
delete *motionStateItr;
|
|
||||||
++motionStateItr;
|
|
||||||
}
|
|
||||||
_motionStates.clear();
|
|
||||||
|
|
||||||
QReadLocker locker(&_hashLock);
|
QReadLocker locker(&_hashLock);
|
||||||
AvatarHash::iterator avatarIterator = _avatarHash.begin();
|
AvatarHash::iterator avatarIterator = _avatarHash.begin();
|
||||||
|
@ -388,9 +367,18 @@ void AvatarManager::deleteAllAvatars() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AvatarManager::deleteMotionStates() {
|
||||||
|
// delete motionstates that were removed from physics last frame
|
||||||
|
for (auto state : _motionStatesToDelete) {
|
||||||
|
delete state;
|
||||||
|
}
|
||||||
|
_motionStatesToDelete.clear();
|
||||||
|
}
|
||||||
|
|
||||||
void AvatarManager::getObjectsToRemoveFromPhysics(VectorOfMotionStates& result) {
|
void AvatarManager::getObjectsToRemoveFromPhysics(VectorOfMotionStates& result) {
|
||||||
result.clear();
|
deleteMotionStates();
|
||||||
result.swap(_motionStatesToRemoveFromPhysics);
|
result = _motionStatesToRemoveFromPhysics;
|
||||||
|
_motionStatesToDelete.swap(_motionStatesToRemoveFromPhysics);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AvatarManager::getObjectsToAddToPhysics(VectorOfMotionStates& result) {
|
void AvatarManager::getObjectsToAddToPhysics(VectorOfMotionStates& result) {
|
||||||
|
|
|
@ -92,7 +92,7 @@ private:
|
||||||
void simulateAvatarFades(float deltaTime);
|
void simulateAvatarFades(float deltaTime);
|
||||||
|
|
||||||
AvatarSharedPointer newSharedAvatar() override;
|
AvatarSharedPointer newSharedAvatar() override;
|
||||||
void removeAvatarFromPhysicsSimulation(Avatar* avatar);
|
void deleteMotionStates();
|
||||||
void handleRemovedAvatar(const AvatarSharedPointer& removedAvatar, KillAvatarReason removalReason = KillAvatarReason::NoReason) override;
|
void handleRemovedAvatar(const AvatarSharedPointer& removedAvatar, KillAvatarReason removalReason = KillAvatarReason::NoReason) override;
|
||||||
|
|
||||||
QVector<AvatarSharedPointer> _avatarsToFade;
|
QVector<AvatarSharedPointer> _avatarsToFade;
|
||||||
|
@ -100,6 +100,7 @@ private:
|
||||||
using AvatarMotionStateMap = QMap<Avatar*, AvatarMotionState*>;
|
using AvatarMotionStateMap = QMap<Avatar*, AvatarMotionState*>;
|
||||||
AvatarMotionStateMap _motionStates;
|
AvatarMotionStateMap _motionStates;
|
||||||
VectorOfMotionStates _motionStatesToRemoveFromPhysics;
|
VectorOfMotionStates _motionStatesToRemoveFromPhysics;
|
||||||
|
VectorOfMotionStates _motionStatesToDelete;
|
||||||
SetOfMotionStates _motionStatesToAddToPhysics;
|
SetOfMotionStates _motionStatesToAddToPhysics;
|
||||||
|
|
||||||
std::shared_ptr<MyAvatar> _myAvatar;
|
std::shared_ptr<MyAvatar> _myAvatar;
|
||||||
|
|
Loading…
Reference in a new issue