Browse Source

Fix JSON issue with .asset files

Josh Engebretson 9 years ago
parent
commit
444c4d1ff7
1 changed files with 12 additions and 4 deletions
  1. 12 4
      Source/Atomic/Resource/JSONFile.cpp

+ 12 - 4
Source/Atomic/Resource/JSONFile.cpp

@@ -185,9 +185,12 @@ static void ToRapidjsonValue(rapidjson::Value& rapidjsonValue, const JSONValue&
 
 
             for (unsigned i = 0; i < jsonArray.Size(); ++i)
             for (unsigned i = 0; i < jsonArray.Size(); ++i)
             {
             {
+// ATOMIC BEGIN
+				// ATOMIC: Set value before adding to array, see note in JSON_OBJECT case below
                 rapidjson::Value value;
                 rapidjson::Value value;
-                rapidjsonValue.PushBack(value, allocator);
-                ToRapidjsonValue(rapidjsonValue[i], jsonArray[i], allocator);
+				ToRapidjsonValue(value, jsonArray[i], allocator);
+                rapidjsonValue.PushBack(value, allocator);                
+// ATOMIC END
             }
             }
         }
         }
         break;
         break;
@@ -199,10 +202,15 @@ static void ToRapidjsonValue(rapidjson::Value& rapidjsonValue, const JSONValue&
             rapidjsonValue.SetObject();
             rapidjsonValue.SetObject();
             for (JSONObject::ConstIterator i = jsonObject.Begin(); i != jsonObject.End(); ++i)
             for (JSONObject::ConstIterator i = jsonObject.Begin(); i != jsonObject.End(); ++i)
             {
             {
+// ATOMIC BEGIN
+				// ATOMIC: Set value before adding member, this fixes a rapidjson crash
+				// when trying to immediately find member (VS2015, release build, difficult to reproduce)
+				// TODO: Submit a PR to upstream
                 const char* name = i->first_.CString();
                 const char* name = i->first_.CString();
                 rapidjson::Value value;
                 rapidjson::Value value;
-                rapidjsonValue.AddMember(name, value, allocator);
-                ToRapidjsonValue(rapidjsonValue[name], i->second_, allocator);
+				ToRapidjsonValue(value, i->second_, allocator);
+                rapidjsonValue.AddMember(name, value, allocator);                
+// ATOMIC END
             }
             }
         }
         }
         break;
         break;