Merge pull request #3462 from Atlante45/fix_attachment_bug_with_recording

Fixes concurrency issue with ScriptEngine timers
This commit is contained in:
Brad Hefta-Gaub 2014-09-21 20:48:05 -07:00
commit 631171eb2e
3 changed files with 13 additions and 9 deletions

View file

@ -877,7 +877,9 @@ void Avatar::setSkeletonModelURL(const QUrl& skeletonModelURL) {
void Avatar::setAttachmentData(const QVector<AttachmentData>& attachmentData) { void Avatar::setAttachmentData(const QVector<AttachmentData>& attachmentData) {
AvatarData::setAttachmentData(attachmentData); AvatarData::setAttachmentData(attachmentData);
if (QThread::currentThread() != thread()) { if (QThread::currentThread() != thread()) {
QMetaObject::invokeMethod(this, "setAttachmentData", Qt::DirectConnection,
Q_ARG(const QVector<AttachmentData>, attachmentData));
return; return;
} }
// make sure we have as many models as attachments // make sure we have as many models as attachments
@ -892,9 +894,9 @@ void Avatar::setAttachmentData(const QVector<AttachmentData>& attachmentData) {
// update the urls // update the urls
for (int i = 0; i < attachmentData.size(); i++) { for (int i = 0; i < attachmentData.size(); i++) {
_attachmentModels[i]->setURL(attachmentData.at(i).modelURL);
_attachmentModels[i]->setSnapModelToCenter(true); _attachmentModels[i]->setSnapModelToCenter(true);
_attachmentModels[i]->setScaleToFit(true, _scale * _attachmentData.at(i).scale); _attachmentModels[i]->setScaleToFit(true, _scale * _attachmentData.at(i).scale);
_attachmentModels[i]->setURL(attachmentData.at(i).modelURL);
} }
} }

View file

@ -1029,7 +1029,9 @@ void MyAvatar::setSkeletonModelURL(const QUrl& skeletonModelURL) {
void MyAvatar::setAttachmentData(const QVector<AttachmentData>& attachmentData) { void MyAvatar::setAttachmentData(const QVector<AttachmentData>& attachmentData) {
Avatar::setAttachmentData(attachmentData); Avatar::setAttachmentData(attachmentData);
if (QThread::currentThread() != thread()) { if (QThread::currentThread() != thread()) {
QMetaObject::invokeMethod(this, "setAttachmentData", Qt::DirectConnection,
Q_ARG(const QVector<AttachmentData>, attachmentData));
return; return;
} }
_billboardValid = false; _billboardValid = false;

View file

@ -605,18 +605,18 @@ void ScriptEngine::stop() {
void ScriptEngine::timerFired() { void ScriptEngine::timerFired() {
QTimer* callingTimer = reinterpret_cast<QTimer*>(sender()); QTimer* callingTimer = reinterpret_cast<QTimer*>(sender());
// call the associated JS function, if it exists
QScriptValue timerFunction = _timerFunctionMap.value(callingTimer); QScriptValue timerFunction = _timerFunctionMap.value(callingTimer);
if (timerFunction.isValid()) {
timerFunction.call();
}
if (!callingTimer->isActive()) { if (!callingTimer->isActive()) {
// this timer is done, we can kill it // this timer is done, we can kill it
_timerFunctionMap.remove(callingTimer); _timerFunctionMap.remove(callingTimer);
delete callingTimer; delete callingTimer;
} }
// call the associated JS function, if it exists
if (timerFunction.isValid()) {
timerFunction.call();
}
} }
QObject* ScriptEngine::setupTimerWithInterval(const QScriptValue& function, int intervalMS, bool isSingleShot) { QObject* ScriptEngine::setupTimerWithInterval(const QScriptValue& function, int intervalMS, bool isSingleShot) {