From 7a16a7a7e4b78be8d3887c1288831488edff83f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matias=20Kangasj=C3=A4rvel=C3=A4?= Date: Fri, 15 May 2020 16:48:41 +0300 Subject: [PATCH] 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. --- code/AssetLib/glTF2/glTF2Asset.inl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/code/AssetLib/glTF2/glTF2Asset.inl b/code/AssetLib/glTF2/glTF2Asset.inl index 5e1cc42d6..e3fff61a7 100644 --- a/code/AssetLib/glTF2/glTF2Asset.inl +++ b/code/AssetLib/glTF2/glTF2Asset.inl @@ -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);