Merge pull request #15489 from luiscuenca/jointIndicesCrashFix

Fix memory corruption in _modelJointIndicesCache QHash
This commit is contained in:
Anthony Thibault 2019-05-01 15:17:08 -07:00 committed by GitHub
commit b0af8b1bdc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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,9 +1439,7 @@ 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); for (auto k = _modelJointIndicesCache.constBegin(); k != _modelJointIndicesCache.constEnd(); k++) {
while (k.hasNext()) {
k.next();
int index = k.value(); int index = k.value();
if (index > maxJointIndex) { if (index > maxJointIndex) {
maxJointIndex = index; maxJointIndex = index;
@ -1450,9 +1448,7 @@ QStringList Avatar::getJointNames() const {
// 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); for (auto i = _modelJointIndicesCache.constBegin(); i != _modelJointIndicesCache.constEnd(); i++) {
while (i.hasNext()) {
i.next();
int index = i.value(); int index = i.value();
resultVector[index] = i.key(); resultVector[index] = i.key();
} }