Fix infinite recursion in gltf2 skin parsing

Previously parsing a node caused the skin that was attached to it
to be parsed, which caused the skins node joints to be parsed,
which could cause the skin to be re-parsed leading to infinite or
at the very least exponential recursion.

The fix is to just get a reference to a temporarily uninitialized
skin as they were being parsed after the scene graph just to be safe
anyway. This way we avoid the recursion problem and all the references
will be valid in the end.
pull/3226/head
Matias Kangasjärvelä 2020-05-15 16:48:41 +03:00
parent b7de061749
commit 7a16a7a7e4
1 changed files with 4 additions and 2 deletions

View File

@ -1188,9 +1188,11 @@ inline void Node::Read(Value &obj, Asset &r) {
}
}
// Do not retrieve a skin here, just take a reference, to avoid infinite recursion
// Skins will be properly loaded later
Value *curSkin = FindUInt(obj, "skin");
if (nullptr != curSkin) {
this->skin = r.skins.Retrieve(curSkin->GetUint());
this->skin = r.skins.Get(curSkin->GetUint());
}
Value *curCamera = FindUInt(obj, "camera");
@ -1481,7 +1483,7 @@ inline void Asset::Load(const std::string &pFile, bool isBinary) {
}
}
// Force reading of skins since they're not always directly referenced
// Read skins after nodes have been loaded to avoid infinite recursion
if (Value *skinsArray = FindArray(doc, "skins")) {
for (unsigned int i = 0; i < skinsArray->Size(); ++i) {
skins.Retrieve(i);