[Bf-blender-cvs] [56a97ba816c] universal-scene-description: USD import: fix crash on empty blendshapes.

Michael Kowalski noreply at git.blender.org
Mon Jan 9 17:34:13 CET 2023


Commit: 56a97ba816c4d4090ded4a9b69c558b362556d89
Author: Michael Kowalski
Date:   Sun Jan 8 20:54:57 2023 -0500
Branches: universal-scene-description
https://developer.blender.org/rB56a97ba816c4d4090ded4a9b69c558b362556d89

USD import: fix crash on empty blendshapes.

Now guarding against an empty offsets array and
out-of-bounds offset indices.

===================================================================

M	source/blender/io/usd/intern/usd_skel_convert.cc

===================================================================

diff --git a/source/blender/io/usd/intern/usd_skel_convert.cc b/source/blender/io/usd/intern/usd_skel_convert.cc
index 69ab05c234e..03535326d84 100644
--- a/source/blender/io/usd/intern/usd_skel_convert.cc
+++ b/source/blender/io/usd/intern/usd_skel_convert.cc
@@ -260,6 +260,11 @@ void import_blendshapes(Main *bmain, Object *obj, pxr::UsdPrim prim)
       continue;
     }
 
+    if (offsets.empty()) {
+      std::cout << "No offsets for blendshape " << path << std::endl;
+      continue;
+    }
+
     shapekey_names.insert(blendshapes[i]);
 
     kb = BKE_keyblock_add(key, blendshapes[i].GetString().c_str());
@@ -274,6 +279,11 @@ void import_blendshapes(Main *bmain, Object *obj, pxr::UsdPrim prim)
 
     if (point_indices.empty()) {
       for (int a = 0; a < kb->totelem; ++a, fp += 3) {
+        if (a >= offsets.size()) {
+          std::cout << "Number of offsets greater than number of mesh vertices for blendshape "
+                    << path << std::endl;
+          break;
+        }
         add_v3_v3(fp, offsets[a].data());
       }
     }
@@ -281,10 +291,14 @@ void import_blendshapes(Main *bmain, Object *obj, pxr::UsdPrim prim)
       int a = 0;
       for (int i : point_indices) {
         if (i < 0 || i > kb->totelem) {
-          std::cout << "out of bounds point index " << i << std::endl;
+          std::cout << "Out of bounds point index " << i << " for blendshape " << path << std::endl;
           ++a;
           continue;
         }
+        if (a >= offsets.size()) {
+          std::cout << "Number of offsets greater than number of mesh vertices for blendshape " << path << std::endl;
+          break;
+        }
         add_v3_v3(&fp[3 * i], offsets[a].data());
         ++a;
       }



More information about the Bf-blender-cvs mailing list