Fix crash accessing _modelJointIndicesCache

This commit is contained in:
luiscuenca 2019-05-01 08:57:09 -07:00
parent 9261df5c24
commit 73454b06a2
No known key found for this signature in database
GPG key ID: 2387ECD129A6961D

View file

@ -1428,7 +1428,7 @@ int Avatar::getJointIndex(const QString& name) const {
withValidJointIndicesCache([&]() { withValidJointIndicesCache([&]() {
if (_modelJointIndicesCache.contains(name)) { if (_modelJointIndicesCache.contains(name)) {
result = _modelJointIndicesCache[name] - 1; result = _modelJointIndicesCache.value(name) - 1;
} }
}); });
return result; return result;
@ -1439,22 +1439,22 @@ QStringList Avatar::getJointNames() const {
withValidJointIndicesCache([&]() { withValidJointIndicesCache([&]() {
// find out how large the vector needs to be // find out how large the vector needs to be
int maxJointIndex = -1; int maxJointIndex = -1;
QHashIterator<QString, int> k(_modelJointIndicesCache); QHash<QString, int>::const_iterator k = _modelJointIndicesCache.constBegin();
while (k.hasNext()) { while (k != _modelJointIndicesCache.constEnd()) {
k.next();
int index = k.value(); int index = k.value();
if (index > maxJointIndex) { if (index > maxJointIndex) {
maxJointIndex = index; maxJointIndex = index;
} }
++k;
} }
// iterate through the hash and put joint names // iterate through the hash and put joint names
// into the vector at their indices // into the vector at their indices
QVector<QString> resultVector(maxJointIndex+1); QVector<QString> resultVector(maxJointIndex+1);
QHashIterator<QString, int> i(_modelJointIndicesCache); QHash<QString, int>::const_iterator i = _modelJointIndicesCache.constBegin();
while (i.hasNext()) { while (i != _modelJointIndicesCache.constEnd()) {
i.next();
int index = i.value(); int index = i.value();
resultVector[index] = i.key(); resultVector[index] = i.key();
++i;
} }
// convert to QList and drop out blanks // convert to QList and drop out blanks
result = resultVector.toList(); result = resultVector.toList();