[Bf-blender-cvs] [177bc807480] blender-v3.3-release: Fix: add attribute with empty string name crash

Ethan-Hall noreply at git.blender.org
Thu Aug 4 00:18:09 CEST 2022


Commit: 177bc807480e85b6dd331a48af379cb795719151
Author: Ethan-Hall
Date:   Wed Aug 3 15:16:46 2022 -0700
Branches: blender-v3.3-release
https://developer.blender.org/rB177bc807480e85b6dd331a48af379cb795719151

Fix: add attribute with empty string name crash

Due to a recent change, empty strings are unhandled. This results
in Blender crashing.

This patch fixes the crash but a discrepancy still exists...
Prior to the regression, the empty string would be replaced by the
name of the data type. This patch uses "Attribute" for the default
name regardless of type. Restoring the previous behavior would
require making and/or modifying API methods.

Regression introduced in: rBeae36be372a6

Reviewed By: Joseph Eagar & Campbell Barton
Differential Revision: https://developer.blender.org/D14734
Ref D14734

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

M	source/blender/blenkernel/intern/attribute.cc

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

diff --git a/source/blender/blenkernel/intern/attribute.cc b/source/blender/blenkernel/intern/attribute.cc
index 639e190a2c6..b6d39486313 100644
--- a/source/blender/blenkernel/intern/attribute.cc
+++ b/source/blender/blenkernel/intern/attribute.cc
@@ -20,9 +20,12 @@
 #include "DNA_pointcloud_types.h"
 
 #include "BLI_index_range.hh"
+#include "BLI_string.h"
 #include "BLI_string_utf8.h"
 #include "BLI_string_utils.h"
 
+#include "BLT_translation.h"
+
 #include "BKE_attribute.h"
 #include "BKE_attribute.hh"
 #include "BKE_curves.hh"
@@ -201,7 +204,14 @@ bool BKE_id_attribute_calc_unique_name(ID *id, const char *name, char *outname)
 {
   AttrUniqueData data{id};
 
-  BLI_strncpy_utf8(outname, name, MAX_CUSTOMDATA_LAYER_NAME);
+  /* Set default name if none specified.
+   * NOTE: We only call IFACE_() if needed to avoid locale lookup overhead. */
+  if (!name || name[0] == '\0') {
+    BLI_strncpy(outname, IFACE_("Attribute"), MAX_CUSTOMDATA_LAYER_NAME);
+  }
+  else {
+    BLI_strncpy_utf8(outname, name, MAX_CUSTOMDATA_LAYER_NAME);
+  }
 
   return BLI_uniquename_cb(
       unique_name_cb, &data, nullptr, '.', outname, MAX_CUSTOMDATA_LAYER_NAME);



More information about the Bf-blender-cvs mailing list