mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 18:21:16 +02:00
Merge pull request #13339 from SamGondelman/avatarHash
Possibly fix avatarHash crash
This commit is contained in:
commit
be28097279
3 changed files with 7 additions and 6 deletions
|
@ -468,13 +468,14 @@ void AvatarManager::updateAvatarRenderStatus(bool shouldRenderAvatars) {
|
||||||
_shouldRender = shouldRenderAvatars;
|
_shouldRender = shouldRenderAvatars;
|
||||||
const render::ScenePointer& scene = qApp->getMain3DScene();
|
const render::ScenePointer& scene = qApp->getMain3DScene();
|
||||||
render::Transaction transaction;
|
render::Transaction transaction;
|
||||||
|
auto avatarHashCopy = getHashCopy();
|
||||||
if (_shouldRender) {
|
if (_shouldRender) {
|
||||||
for (auto avatarData : _avatarHash) {
|
for (auto avatarData : avatarHashCopy) {
|
||||||
auto avatar = std::static_pointer_cast<Avatar>(avatarData);
|
auto avatar = std::static_pointer_cast<Avatar>(avatarData);
|
||||||
avatar->addToScene(avatar, scene, transaction);
|
avatar->addToScene(avatar, scene, transaction);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (auto avatarData : _avatarHash) {
|
for (auto avatarData : avatarHashCopy) {
|
||||||
auto avatar = std::static_pointer_cast<Avatar>(avatarData);
|
auto avatar = std::static_pointer_cast<Avatar>(avatarData);
|
||||||
avatar->removeFromScene(avatar, scene, transaction);
|
avatar->removeFromScene(avatar, scene, transaction);
|
||||||
}
|
}
|
||||||
|
@ -514,7 +515,8 @@ RayToAvatarIntersectionResult AvatarManager::findRayIntersectionVector(const Pic
|
||||||
|
|
||||||
glm::vec3 normDirection = glm::normalize(ray.direction);
|
glm::vec3 normDirection = glm::normalize(ray.direction);
|
||||||
|
|
||||||
for (auto avatarData : _avatarHash) {
|
auto avatarHashCopy = getHashCopy();
|
||||||
|
for (auto avatarData : avatarHashCopy) {
|
||||||
auto avatar = std::static_pointer_cast<Avatar>(avatarData);
|
auto avatar = std::static_pointer_cast<Avatar>(avatarData);
|
||||||
if ((avatarsToInclude.size() > 0 && !avatarsToInclude.contains(avatar->getID())) ||
|
if ((avatarsToInclude.size() > 0 && !avatarsToInclude.contains(avatar->getID())) ||
|
||||||
(avatarsToDiscard.size() > 0 && avatarsToDiscard.contains(avatar->getID()))) {
|
(avatarsToDiscard.size() > 0 && avatarsToDiscard.contains(avatar->getID()))) {
|
||||||
|
|
|
@ -82,6 +82,7 @@ AvatarSharedPointer AvatarHashMap::addAvatar(const QUuid& sessionUUID, const QWe
|
||||||
avatar->setSessionUUID(sessionUUID);
|
avatar->setSessionUUID(sessionUUID);
|
||||||
avatar->setOwningAvatarMixer(mixerWeakPointer);
|
avatar->setOwningAvatarMixer(mixerWeakPointer);
|
||||||
|
|
||||||
|
// addAvatar is only called from newOrExistingAvatar, which already locks _hashLock
|
||||||
_avatarHash.insert(sessionUUID, avatar);
|
_avatarHash.insert(sessionUUID, avatar);
|
||||||
emit avatarAddedEvent(sessionUUID);
|
emit avatarAddedEvent(sessionUUID);
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ class AvatarHashMap : public QObject, public Dependency {
|
||||||
public:
|
public:
|
||||||
AvatarHash getHashCopy() { QReadLocker lock(&_hashLock); return _avatarHash; }
|
AvatarHash getHashCopy() { QReadLocker lock(&_hashLock); return _avatarHash; }
|
||||||
const AvatarHash getHashCopy() const { QReadLocker lock(&_hashLock); return _avatarHash; }
|
const AvatarHash getHashCopy() const { QReadLocker lock(&_hashLock); return _avatarHash; }
|
||||||
int size() { return _avatarHash.size(); }
|
int size() { QReadLocker lock(&_hashLock); return _avatarHash.size(); }
|
||||||
|
|
||||||
// Currently, your own avatar will be included as the null avatar id.
|
// Currently, your own avatar will be included as the null avatar id.
|
||||||
|
|
||||||
|
@ -152,8 +152,6 @@ protected:
|
||||||
virtual void handleRemovedAvatar(const AvatarSharedPointer& removedAvatar, KillAvatarReason removalReason = KillAvatarReason::NoReason);
|
virtual void handleRemovedAvatar(const AvatarSharedPointer& removedAvatar, KillAvatarReason removalReason = KillAvatarReason::NoReason);
|
||||||
|
|
||||||
AvatarHash _avatarHash;
|
AvatarHash _avatarHash;
|
||||||
// "Case-based safety": Most access to the _avatarHash is on the same thread. Write access is protected by a write-lock.
|
|
||||||
// If you read from a different thread, you must read-lock the _hashLock. (Scripted write access is not supported).
|
|
||||||
mutable QReadWriteLock _hashLock;
|
mutable QReadWriteLock _hashLock;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in a new issue