mirror of
https://github.com/lubosz/overte.git
synced 2025-04-10 04:52:17 +02:00
Fix for crash in AnimSkeleton::getNumJoints()
When initAnimGraph is called it asynchronously loads the Animation graph in the background. If the model url is changed, or the Model is deleted in between the initial load and it's completion, It's possible to access a bad Rig::_animSkeleton pointer. The fix is to hold onto the _animSkeleton pointer via a weak ref.
This commit is contained in:
parent
a75010fb94
commit
e2df9e29e2
2 changed files with 12 additions and 3 deletions
|
@ -1641,9 +1641,17 @@ void Rig::initAnimGraph(const QUrl& url) {
|
|||
// load the anim graph
|
||||
_animLoader.reset(new AnimNodeLoader(url));
|
||||
_animLoading = true;
|
||||
connect(_animLoader.get(), &AnimNodeLoader::success, [this](AnimNode::Pointer nodeIn) {
|
||||
std::weak_ptr<AnimSkeleton> weakSkeletonPtr = _animSkeleton;
|
||||
connect(_animLoader.get(), &AnimNodeLoader::success, [this, weakSkeletonPtr](AnimNode::Pointer nodeIn) {
|
||||
_animNode = nodeIn;
|
||||
_animNode->setSkeleton(_animSkeleton);
|
||||
|
||||
// abort load if the previous skeleton was deleted.
|
||||
auto sharedSkeletonPtr = weakSkeletonPtr.lock();
|
||||
if (!sharedSkeletonPtr) {
|
||||
return;
|
||||
}
|
||||
|
||||
_animNode->setSkeleton(sharedSkeletonPtr);
|
||||
|
||||
if (_userAnimState.clipNodeEnum != UserAnimState::None) {
|
||||
// restore the user animation we had before reset.
|
||||
|
@ -1651,6 +1659,7 @@ void Rig::initAnimGraph(const QUrl& url) {
|
|||
_userAnimState = { UserAnimState::None, "", 30.0f, false, 0.0f, 0.0f };
|
||||
overrideAnimation(origState.url, origState.fps, origState.loop, origState.firstFrame, origState.lastFrame);
|
||||
}
|
||||
|
||||
// restore the role animations we had before reset.
|
||||
for (auto& roleAnimState : _roleAnimStates) {
|
||||
auto roleState = roleAnimState.second;
|
||||
|
|
|
@ -31,7 +31,7 @@ class AnimInverseKinematics;
|
|||
// Rig instances are reentrant.
|
||||
// However only specific methods thread-safe. Noted below.
|
||||
|
||||
class Rig : public QObject, public std::enable_shared_from_this<Rig> {
|
||||
class Rig : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
struct StateHandler {
|
||||
|
|
Loading…
Reference in a new issue