From 5847f86db8e3598bd6be32bb5110a62991d1adb7 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Wed, 8 Mar 2017 16:12:03 -0800 Subject: [PATCH 1/2] fix crash when unpacking too many joints --- libraries/animation/src/Rig.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/libraries/animation/src/Rig.cpp b/libraries/animation/src/Rig.cpp index b70d28fc30..5573f5c0fe 100644 --- a/libraries/animation/src/Rig.cpp +++ b/libraries/animation/src/Rig.cpp @@ -1310,17 +1310,18 @@ void Rig::copyJointsFromJointData(const QVector& jointDataVec) { if (!_animSkeleton) { return; } - if (jointDataVec.size() != (int)_internalPoseSet._relativePoses.size()) { - // animations haven't fully loaded yet. - _internalPoseSet._relativePoses = _animSkeleton->getRelativeDefaultPoses(); + int numJoints = jointDataVec.size(); + const AnimPoseVec& absoluteDefaultPoses = _animSkeleton->getAbsoluteDefaultPoses(); + if (numJoints != (int)absoluteDefaultPoses.size()) { + // jointData is incompatible + return; } // make a vector of rotations in absolute-geometry-frame - const AnimPoseVec& absoluteDefaultPoses = _animSkeleton->getAbsoluteDefaultPoses(); std::vector rotations; - rotations.reserve(absoluteDefaultPoses.size()); + rotations.reserve(numJoints); const glm::quat rigToGeometryRot(glmExtractRotation(_rigToGeometryTransform)); - for (int i = 0; i < jointDataVec.size(); i++) { + for (int i = 0; i < numJoints; i++) { const JointData& data = jointDataVec.at(i); if (data.rotationSet) { // JointData rotations are in absolute rig-frame so we rotate them to absolute geometry-frame @@ -1334,8 +1335,11 @@ void Rig::copyJointsFromJointData(const QVector& jointDataVec) { _animSkeleton->convertAbsoluteRotationsToRelative(rotations); // store new relative poses + if (numJoints != _internalPoseSet._relativePoses.size()) { + _internalPoseSet._relativePoses = _animSkeleton->getRelativeDefaultPoses(); + } const AnimPoseVec& relativeDefaultPoses = _animSkeleton->getRelativeDefaultPoses(); - for (int i = 0; i < jointDataVec.size(); i++) { + for (int i = 0; i < numJoints; i++) { const JointData& data = jointDataVec.at(i); _internalPoseSet._relativePoses[i].scale() = Vectors::ONE; _internalPoseSet._relativePoses[i].rot() = rotations[i]; From 30d7ffb303925a2f0c7db6ed9e010742ffe43f61 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Wed, 8 Mar 2017 17:17:49 -0800 Subject: [PATCH 2/2] fix warning about signed unsigned compare --- libraries/animation/src/Rig.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/animation/src/Rig.cpp b/libraries/animation/src/Rig.cpp index 5573f5c0fe..9ecd0f6352 100644 --- a/libraries/animation/src/Rig.cpp +++ b/libraries/animation/src/Rig.cpp @@ -1335,7 +1335,7 @@ void Rig::copyJointsFromJointData(const QVector& jointDataVec) { _animSkeleton->convertAbsoluteRotationsToRelative(rotations); // store new relative poses - if (numJoints != _internalPoseSet._relativePoses.size()) { + if (numJoints != (int)_internalPoseSet._relativePoses.size()) { _internalPoseSet._relativePoses = _animSkeleton->getRelativeDefaultPoses(); } const AnimPoseVec& relativeDefaultPoses = _animSkeleton->getRelativeDefaultPoses();