Fix concurrent access crash in avatar mixer

This commit is contained in:
Atlante45 2018-01-08 17:18:16 -08:00
parent 2fddace71e
commit 776a2e8373
2 changed files with 15 additions and 7 deletions

View file

@ -116,8 +116,9 @@ public:
void setLastOtherAvatarEncodeTime(const QUuid& otherAvatar, const uint64_t& time); void setLastOtherAvatarEncodeTime(const QUuid& otherAvatar, const uint64_t& time);
QVector<JointData>& getLastOtherAvatarSentJoints(QUuid otherAvatar) { QVector<JointData>& getLastOtherAvatarSentJoints(QUuid otherAvatar) {
_lastOtherAvatarSentJoints[otherAvatar].resize(_avatar->getJointCount()); auto& lastOtherAvatarSentJoints = _lastOtherAvatarSentJoints[otherAvatar];
return _lastOtherAvatarSentJoints[otherAvatar]; lastOtherAvatarSentJoints.resize(_avatar->getJointCount());
return lastOtherAvatarSentJoints;
} }
void queuePacket(QSharedPointer<ReceivedMessage> message, SharedNodePointer node); void queuePacket(QSharedPointer<ReceivedMessage> message, SharedNodePointer node);

View file

@ -530,9 +530,13 @@ QByteArray AvatarData::toByteArray(AvatarDataDetail dataDetail, quint64 lastSent
destinationBuffer += numValidityBytes; // Move pointer past the validity bytes destinationBuffer += numValidityBytes; // Move pointer past the validity bytes
// sentJointDataOut and lastSentJointData might be the same vector
// build sentJointDataOut locally and then swap it at the end.
QVector<JointData> localSentJointDataOut;
if (sentJointDataOut) { if (sentJointDataOut) {
sentJointDataOut->resize(_jointData.size()); // Make sure the destination is resized before using it localSentJointDataOut.resize(numJoints); // Make sure the destination is resized before using it
} }
float minRotationDOT = !distanceAdjust ? AVATAR_MIN_ROTATION_DOT : getDistanceBasedMinRotationDOT(viewerPosition); float minRotationDOT = !distanceAdjust ? AVATAR_MIN_ROTATION_DOT : getDistanceBasedMinRotationDOT(viewerPosition);
for (int i = 0; i < _jointData.size(); i++) { for (int i = 0; i < _jointData.size(); i++) {
@ -552,8 +556,7 @@ QByteArray AvatarData::toByteArray(AvatarDataDetail dataDetail, quint64 lastSent
destinationBuffer += packOrientationQuatToSixBytes(destinationBuffer, data.rotation); destinationBuffer += packOrientationQuatToSixBytes(destinationBuffer, data.rotation);
if (sentJointDataOut) { if (sentJointDataOut) {
auto jointDataOut = *sentJointDataOut; localSentJointDataOut[i].rotation = data.rotation;
jointDataOut[i].rotation = data.rotation;
} }
} }
@ -602,8 +605,7 @@ QByteArray AvatarData::toByteArray(AvatarDataDetail dataDetail, quint64 lastSent
packFloatVec3ToSignedTwoByteFixed(destinationBuffer, data.translation, TRANSLATION_COMPRESSION_RADIX); packFloatVec3ToSignedTwoByteFixed(destinationBuffer, data.translation, TRANSLATION_COMPRESSION_RADIX);
if (sentJointDataOut) { if (sentJointDataOut) {
auto jointDataOut = *sentJointDataOut; localSentJointDataOut[i].translation = data.translation;
jointDataOut[i].translation = data.translation;
} }
} }
@ -646,6 +648,11 @@ QByteArray AvatarData::toByteArray(AvatarDataDetail dataDetail, quint64 lastSent
if (outboundDataRateOut) { if (outboundDataRateOut) {
outboundDataRateOut->jointDataRate.increment(numBytes); outboundDataRateOut->jointDataRate.increment(numBytes);
} }
if (sentJointDataOut) {
// Push new sent joint data to sentJointDataOut
sentJointDataOut->swap(localSentJointDataOut);
}
} }
int avatarDataSize = destinationBuffer - startPosition; int avatarDataSize = destinationBuffer - startPosition;