diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index cc850eab9e..adfde2936b 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -704,19 +704,46 @@ float loadSetting(QSettings& settings, const char* name, float defaultValue) { return value; } +// Resource loading is not yet thread safe. If an animation is not loaded when requested by other than tha main thread, +// we block in AnimationHandle::setURL => AnimationCache::getAnimation. +// Meanwhile, the main thread will also eventually lock as it tries to render us. +// If we demand the animation from the update thread while we're locked, we'll deadlock. +// Until we untangle this, code puts the updates back on the main thread temporarilly and starts all the loading. +void MyAvatar::safelyLoadAnimations() { + qApp->setAvatarUpdateThreading(false); + _rig->addAnimationByRole("idle"); + _rig->addAnimationByRole("walk"); + _rig->addAnimationByRole("backup"); + _rig->addAnimationByRole("leftTurn"); + _rig->addAnimationByRole("rightTurn"); + _rig->addAnimationByRole("leftStrafe"); + _rig->addAnimationByRole("rightStrafe"); +} + void MyAvatar::setEnableRigAnimations(bool isEnabled) { + if (isEnabled) { + safelyLoadAnimations(); + } _rig->setEnableRig(isEnabled); if (!isEnabled) { _rig->deleteAnimations(); + } else if (Menu::getInstance()->isOptionChecked(MenuOption::EnableAvatarUpdateThreading)) { + qApp->setAvatarUpdateThreading(true); } } void MyAvatar::setEnableAnimGraph(bool isEnabled) { + if (isEnabled) { + safelyLoadAnimations(); + } _rig->setEnableAnimGraph(isEnabled); if (isEnabled) { if (_skeletonModel.readyToAddToScene()) { initAnimGraph(); } + if (Menu::getInstance()->isOptionChecked(MenuOption::EnableAvatarUpdateThreading)) { + qApp->setAvatarUpdateThreading(true); + } } else { destroyAnimGraph(); } diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index ffa93ed13c..5fdfe000e3 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -292,6 +292,7 @@ private: void initHeadBones(); void initAnimGraph(); void destroyAnimGraph(); + void safelyLoadAnimations(); // Avatar Preferences QUrl _fullAvatarURLFromPreferences;