mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-05-28 07:19:55 +02:00
Merge pull request #15654 from AndrewMeadows/fix-crash-bugz420
BUGZ-420: guard MyAvatar::_scriptEngine with mutex
This commit is contained in:
commit
fa8d2ffe65
2 changed files with 21 additions and 11 deletions
|
@ -325,8 +325,8 @@ MyAvatar::MyAvatar(QThread* thread) :
|
||||||
|
|
||||||
MyAvatar::~MyAvatar() {
|
MyAvatar::~MyAvatar() {
|
||||||
_lookAtTargetAvatar.reset();
|
_lookAtTargetAvatar.reset();
|
||||||
delete _myScriptEngine;
|
delete _scriptEngine;
|
||||||
_myScriptEngine = nullptr;
|
_scriptEngine = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString MyAvatar::getDominantHand() const {
|
QString MyAvatar::getDominantHand() const {
|
||||||
|
@ -1598,7 +1598,8 @@ void MyAvatar::handleChangedAvatarEntityData() {
|
||||||
blobFailed = true; // blob doesn't exist
|
blobFailed = true; // blob doesn't exist
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!EntityItemProperties::blobToProperties(*_myScriptEngine, itr.value(), properties)) {
|
std::lock_guard<std::mutex> guard(_scriptEngineLock);
|
||||||
|
if (!EntityItemProperties::blobToProperties(*_scriptEngine, itr.value(), properties)) {
|
||||||
blobFailed = true; // blob is corrupt
|
blobFailed = true; // blob is corrupt
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1630,7 +1631,8 @@ void MyAvatar::handleChangedAvatarEntityData() {
|
||||||
skip = true;
|
skip = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!EntityItemProperties::blobToProperties(*_myScriptEngine, itr.value(), properties)) {
|
std::lock_guard<std::mutex> guard(_scriptEngineLock);
|
||||||
|
if (!EntityItemProperties::blobToProperties(*_scriptEngine, itr.value(), properties)) {
|
||||||
skip = true;
|
skip = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1737,7 +1739,10 @@ bool MyAvatar::updateStaleAvatarEntityBlobs() const {
|
||||||
if (found) {
|
if (found) {
|
||||||
++numFound;
|
++numFound;
|
||||||
QByteArray blob;
|
QByteArray blob;
|
||||||
EntityItemProperties::propertiesToBlob(*_myScriptEngine, getID(), properties, blob);
|
{
|
||||||
|
std::lock_guard<std::mutex> guard(_scriptEngineLock);
|
||||||
|
EntityItemProperties::propertiesToBlob(*_scriptEngine, getID(), properties, blob);
|
||||||
|
}
|
||||||
_avatarEntitiesLock.withWriteLock([&] {
|
_avatarEntitiesLock.withWriteLock([&] {
|
||||||
_cachedAvatarEntityBlobs[id] = blob;
|
_cachedAvatarEntityBlobs[id] = blob;
|
||||||
});
|
});
|
||||||
|
@ -1883,8 +1888,8 @@ void MyAvatar::avatarEntityDataToJson(QJsonObject& root) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyAvatar::loadData() {
|
void MyAvatar::loadData() {
|
||||||
if (!_myScriptEngine) {
|
if (!_scriptEngine) {
|
||||||
_myScriptEngine = new QScriptEngine();
|
_scriptEngine = new QScriptEngine();
|
||||||
}
|
}
|
||||||
getHead()->setBasePitch(_headPitchSetting.get());
|
getHead()->setBasePitch(_headPitchSetting.get());
|
||||||
|
|
||||||
|
@ -2476,14 +2481,18 @@ QVariantList MyAvatar::getAvatarEntitiesVariant() {
|
||||||
if (!entity) {
|
if (!entity) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
QVariantMap avatarEntityData;
|
|
||||||
EncodeBitstreamParams params;
|
EncodeBitstreamParams params;
|
||||||
auto desiredProperties = entity->getEntityProperties(params);
|
auto desiredProperties = entity->getEntityProperties(params);
|
||||||
desiredProperties += PROP_LOCAL_POSITION;
|
desiredProperties += PROP_LOCAL_POSITION;
|
||||||
desiredProperties += PROP_LOCAL_ROTATION;
|
desiredProperties += PROP_LOCAL_ROTATION;
|
||||||
EntityItemProperties entityProperties = entity->getProperties(desiredProperties);
|
QVariantMap avatarEntityData;
|
||||||
QScriptValue scriptProperties = EntityItemPropertiesToScriptValue(_myScriptEngine, entityProperties);
|
|
||||||
avatarEntityData["id"] = entityID;
|
avatarEntityData["id"] = entityID;
|
||||||
|
EntityItemProperties entityProperties = entity->getProperties(desiredProperties);
|
||||||
|
QScriptValue scriptProperties;
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> guard(_scriptEngineLock);
|
||||||
|
scriptProperties = EntityItemPropertiesToScriptValue(_scriptEngine, entityProperties);
|
||||||
|
}
|
||||||
avatarEntityData["properties"] = scriptProperties.toVariant();
|
avatarEntityData["properties"] = scriptProperties.toVariant();
|
||||||
avatarEntitiesData.append(QVariant(avatarEntityData));
|
avatarEntitiesData.append(QVariant(avatarEntityData));
|
||||||
}
|
}
|
||||||
|
|
|
@ -2741,7 +2741,8 @@ private:
|
||||||
mutable std::set<QUuid> _staleCachedAvatarEntityBlobs;
|
mutable std::set<QUuid> _staleCachedAvatarEntityBlobs;
|
||||||
//
|
//
|
||||||
// keep a ScriptEngine around so we don't have to instantiate on the fly (these are very slow to create/delete)
|
// keep a ScriptEngine around so we don't have to instantiate on the fly (these are very slow to create/delete)
|
||||||
QScriptEngine* _myScriptEngine { nullptr };
|
mutable std::mutex _scriptEngineLock;
|
||||||
|
QScriptEngine* _scriptEngine { nullptr };
|
||||||
bool _needToSaveAvatarEntitySettings { false };
|
bool _needToSaveAvatarEntitySettings { false };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue