Fix svace issue to nullcheck
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / public-api / loader / dli-loader.cpp
index ca28c83..96555f2 100644 (file)
@@ -407,83 +407,86 @@ void DliLoader::Impl::ParseScene(LoadParams& params)
 
   // get index of root node.
   auto docRoot = mParser.GetRoot();
-
-  // Process resources first - these are shared
-  if(auto environments = docRoot->GetChild("environment"))
+  if(docRoot)
   {
-    ParseEnvironments(environments, output.mResources); // NOTE: must precede parsing of materials
-  }
+    // Process resources first - these are shared
+    if(auto environments = docRoot->GetChild("environment"))
+    {
+      ParseEnvironments(environments, output.mResources); // NOTE: must precede parsing of materials
+    }
 
-  if(auto meshes = docRoot->GetChild("meshes"))
-  {
-    ParseMeshes(meshes, output.mResources);
-  }
+    if(auto meshes = docRoot->GetChild("meshes"))
+    {
+      ParseMeshes(meshes, output.mResources);
+    }
 
-  if(auto shaders = docRoot->GetChild("shaders"))
-  {
-    ParseShaders(shaders, output.mResources);
-  }
+    if(auto shaders = docRoot->GetChild("shaders"))
+    {
+      ParseShaders(shaders, output.mResources);
+    }
 
-  if(auto materials = docRoot->GetChild("materials"))
-  {
-    ParseMaterials(materials, input.mConvertColorCode, output.mResources);
-  }
+    if(auto materials = docRoot->GetChild("materials"))
+    {
+      ParseMaterials(materials, input.mConvertColorCode, output.mResources);
+    }
 
-  for(auto& c : input.mPreNodeCategoryProcessors)
-  {
-    if(auto node = docRoot->GetChild(c.first))
+    for(auto& c : input.mPreNodeCategoryProcessors)
     {
-      Property::Array array;
-      ParseProperties(*node, array);
-      c.second(std::move(array), mOnError);
+      if(auto node = docRoot->GetChild(c.first))
+      {
+        Property::Array array;
+        ParseProperties(*node, array);
+        c.second(std::move(array), mOnError);
+      }
     }
-  }
 
-  // Process scenes
-  Index iScene = 0; // default scene
-  ReadIndex(docRoot->GetChild("scene"), iScene);
+    // Process scenes
+    Index iScene = 0; // default scene
+    ReadIndex(docRoot->GetChild("scene"), iScene);
 
-  auto tnScenes = RequireChild(docRoot, "scenes");
-  auto tnNodes  = RequireChild(docRoot, "nodes");
-  ParseSceneInternal(iScene, tnScenes, tnNodes, params);
+    auto tnScenes = RequireChild(docRoot, "scenes");
+    auto tnNodes  = RequireChild(docRoot, "nodes");
+    ParseSceneInternal(iScene, tnScenes, tnNodes, params);
 
-  ParseSkeletons(docRoot->GetChild("skeletons"), output.mScene, output.mResources);
+    ParseSkeletons(docRoot->GetChild("skeletons"), output.mScene, output.mResources);
 
-  output.mScene.EnsureUniqueSkinningShaderInstances(output.mResources);
-  output.mScene.EnsureUniqueBlendShapeShaderInstances(output.mResources);
+    output.mScene.EnsureUniqueSkinningShaderInstances(output.mResources);
+    output.mScene.EnsureUniqueBlendShapeShaderInstances(output.mResources);
 
-  // Ger cameras and lights
-  GetCameraParameters(output.mCameraParameters);
-  GetLightParameters(output.mLightParameters);
+    // Ger cameras and lights
+    GetCameraParameters(output.mCameraParameters);
+    GetLightParameters(output.mLightParameters);
 
-  // Post-node processors and animations last
-  for(auto& c : input.mPostNodeCategoryProcessors)
-  {
-    if(auto node = docRoot->GetChild(c.first))
+    // Post-node processors and animations last
+    for(auto& c : input.mPostNodeCategoryProcessors)
     {
-      Property::Array array;
-      ParseProperties(*node, array);
-      c.second(std::move(array), mOnError);
+      if(auto node = docRoot->GetChild(c.first))
+      {
+        Property::Array array;
+        ParseProperties(*node, array);
+        c.second(std::move(array), mOnError);
+      }
     }
-  }
 
-  if(auto animations = docRoot->GetChild("animations"))
-  {
-    ParseAnimations(animations, params);
-  }
+    if(auto animations = docRoot->GetChild("animations"))
+    {
+      ParseAnimations(animations, params);
+    }
 
-  if(!output.mAnimationDefinitions.empty())
-  {
-    if(auto animationGroups = docRoot->GetChild("animationGroups"))
+    if(!output.mAnimationDefinitions.empty())
     {
-      ParseAnimationGroups(animationGroups, params);
+      if(auto animationGroups = docRoot->GetChild("animationGroups"))
+      {
+        ParseAnimationGroups(animationGroups, params);
+      }
     }
   }
 }
 
 void DliLoader::Impl::ParseSceneInternal(Index iScene, const Toolkit::TreeNode* tnScenes, const Toolkit::TreeNode* tnNodes, LoadParams& params)
 {
-  auto getSceneRootIdx = [tnScenes, tnNodes](Index iScene) {
+  auto getSceneRootIdx = [tnScenes, tnNodes](Index iScene)
+  {
     auto tn = GetNthChild(tnScenes, iScene); // now a "scene" object
     if(!tn)
     {
@@ -1715,95 +1718,101 @@ void DliLoader::Impl::ParseAnimationGroups(const Toolkit::TreeNode* tnAnimationG
 
 void DliLoader::Impl::GetCameraParameters(std::vector<CameraParameters>& cameras) const
 {
-  if(const TreeNode* jsonCameras = mParser.GetRoot()->GetChild("cameras"))
+  if(mParser.GetRoot())
   {
-    cameras.resize(jsonCameras->Size());
-    auto iCamera = cameras.begin();
-    for(auto i0 = jsonCameras->CBegin(), i1 = jsonCameras->CEnd(); i0 != i1; ++i0)
+    if(const TreeNode* jsonCameras = mParser.GetRoot()->GetChild("cameras"))
     {
-      auto& jsonCamera = (*i0).second;
-
-      ReadFloat(jsonCamera.GetChild("fov"), iCamera->yFov);
-      ReadFloat(jsonCamera.GetChild("near"), iCamera->zNear);
-      ReadFloat(jsonCamera.GetChild("far"), iCamera->zFar);
-      if(ReadVector(jsonCamera.GetChild("orthographic"), iCamera->orthographicSize.AsFloat(), 4u))
+      cameras.resize(jsonCameras->Size());
+      auto iCamera = cameras.begin();
+      for(auto i0 = jsonCameras->CBegin(), i1 = jsonCameras->CEnd(); i0 != i1; ++i0)
       {
-        iCamera->isPerspective = false;
-      }
+        auto& jsonCamera = (*i0).second;
 
-      if(auto jsonMatrix = jsonCamera.GetChild("matrix"))
-      {
-        ReadVector(jsonMatrix, iCamera->matrix.AsFloat(), 16u);
-      }
+        ReadFloat(jsonCamera.GetChild("fov"), iCamera->yFov);
+        ReadFloat(jsonCamera.GetChild("near"), iCamera->zNear);
+        ReadFloat(jsonCamera.GetChild("far"), iCamera->zFar);
+        if(ReadVector(jsonCamera.GetChild("orthographic"), iCamera->orthographicSize.AsFloat(), 4u))
+        {
+          iCamera->isPerspective = false;
+        }
+
+        if(auto jsonMatrix = jsonCamera.GetChild("matrix"))
+        {
+          ReadVector(jsonMatrix, iCamera->matrix.AsFloat(), 16u);
+        }
 
-      ++iCamera;
+        ++iCamera;
+      }
     }
   }
 }
 
 void DliLoader::Impl::GetLightParameters(std::vector<LightParameters>& lights) const
 {
-  if(const TreeNode* jsonLights = mParser.GetRoot()->GetChild("lights"))
+  if(mParser.GetRoot())
   {
-    lights.resize(jsonLights->Size());
-    auto iLight = lights.begin();
-    for(auto i0 = jsonLights->CBegin(), i1 = jsonLights->CEnd(); i0 != i1; ++i0)
+    if(const TreeNode* jsonLights = mParser.GetRoot()->GetChild("lights"))
     {
-      auto& jsonLight = (*i0).second;
-      if(!ReadVector(jsonLight.GetChild("matrix"), iLight->transform.AsFloat(), 16))
+      lights.resize(jsonLights->Size());
+      auto iLight = lights.begin();
+      for(auto i0 = jsonLights->CBegin(), i1 = jsonLights->CEnd(); i0 != i1; ++i0)
       {
-        mOnError(
-          FormatString("Failed to parse light %d - \"matrix\" child with 16 floats expected.\n",
-                       std::distance(jsonLights->CBegin(), i0)));
-        continue;
-      }
+        auto& jsonLight = (*i0).second;
+        if(!ReadVector(jsonLight.GetChild("matrix"), iLight->transform.AsFloat(), 16))
+        {
+          mOnError(
+            FormatString("Failed to parse light %d - \"matrix\" child with 16 floats expected.\n",
+                         std::distance(jsonLights->CBegin(), i0)));
+          continue;
+        }
 
-      int shadowMapSize = 0;
-      if(ReadInt(jsonLight.GetChild(SHADOW_MAP_SIZE), shadowMapSize) && shadowMapSize < 0)
-      {
-        mOnError(
-          FormatString("Failed to parse light %d - %s has an invalid value.",
-                       std::distance(jsonLights->CBegin(), i0),
-                       SHADOW_MAP_SIZE));
-        continue;
-      }
-      iLight->shadowMapSize = shadowMapSize;
+        int shadowMapSize = 0;
+        if(ReadInt(jsonLight.GetChild(SHADOW_MAP_SIZE), shadowMapSize) && shadowMapSize < 0)
+        {
+          mOnError(
+            FormatString("Failed to parse light %d - %s has an invalid value.",
+                         std::distance(jsonLights->CBegin(), i0),
+                         SHADOW_MAP_SIZE));
+          continue;
+        }
+        iLight->shadowMapSize = shadowMapSize;
 
-      float orthoSize = 0.f;
-      if(ReadFloat(jsonLight.GetChild(ORTHOGRAPHIC_SIZE), orthoSize) &&
-         (orthoSize < .0f || std::isnan(orthoSize) || std::isinf(orthoSize)))
-      {
-        mOnError(
-          FormatString("Failed to parse light %d - %s has an invalid value.",
-                       std::distance(jsonLights->CBegin(), i0),
-                       ORTHOGRAPHIC_SIZE));
-        continue;
-      }
-      iLight->orthographicSize = orthoSize;
+        float orthoSize = 0.f;
+        if(ReadFloat(jsonLight.GetChild(ORTHOGRAPHIC_SIZE), orthoSize) &&
+           (orthoSize < .0f || std::isnan(orthoSize) || std::isinf(orthoSize)))
+        {
+          mOnError(
+            FormatString("Failed to parse light %d - %s has an invalid value.",
+                         std::distance(jsonLights->CBegin(), i0),
+                         ORTHOGRAPHIC_SIZE));
+          continue;
+        }
+        iLight->orthographicSize = orthoSize;
 
-      if((iLight->shadowMapSize > 0) != (iLight->orthographicSize > .0f))
-      {
-        mOnError(FormatString(
-          "Light %d: Both shadow map size and orthographic size must be set for shadows to work.",
-          std::distance(jsonLights->CBegin(), i0)));
-      }
+        if((iLight->shadowMapSize > 0) != (iLight->orthographicSize > .0f))
+        {
+          mOnError(FormatString(
+            "Light %d: Both shadow map size and orthographic size must be set for shadows to work.",
+            std::distance(jsonLights->CBegin(), i0)));
+        }
 
-      if(!ReadVector(jsonLight.GetChild("color"), iLight->color.AsFloat(), 3)) // color is optional
-      {
-        iLight->color = Vector3::ONE; // default to white
-      }
+        if(!ReadVector(jsonLight.GetChild("color"), iLight->color.AsFloat(), 3)) // color is optional
+        {
+          iLight->color = Vector3::ONE; // default to white
+        }
 
-      if(!ReadFloat(jsonLight.GetChild("intensity"), iLight->intensity)) // intensity is optional
-      {
-        iLight->intensity = 1.0f; // default to 1.0
-      }
+        if(!ReadFloat(jsonLight.GetChild("intensity"), iLight->intensity)) // intensity is optional
+        {
+          iLight->intensity = 1.0f; // default to 1.0
+        }
 
-      if(!ReadFloat(jsonLight.GetChild("shadowIntensity"), iLight->shadowIntensity)) // intensity is optional
-      {
-        iLight->shadowIntensity = 1.0f; // default to 1.0
-      }
+        if(!ReadFloat(jsonLight.GetChild("shadowIntensity"), iLight->shadowIntensity)) // intensity is optional
+        {
+          iLight->shadowIntensity = 1.0f; // default to 1.0
+        }
 
-      ++iLight;
+        ++iLight;
+      }
     }
   }
 }