[Bf-blender-cvs] [f28adaef520] master: Fix T80747: New vgroups on unsupported object types fails silently

Campbell Barton noreply at git.blender.org
Mon Sep 14 10:27:49 CEST 2020


Commit: f28adaef520c85ab1ea8bc1fb149045a38967431
Author: Campbell Barton
Date:   Mon Sep 14 18:25:54 2020 +1000
Branches: master
https://developer.blender.org/rBf28adaef520c85ab1ea8bc1fb149045a38967431

Fix T80747: New vgroups on unsupported object types fails silently

Raise an exceptions when adding vertex groups to object types
that don't support it.

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

M	source/blender/makesrna/intern/rna_object.c

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

diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c
index c7f625e2fa5..77200ce7eda 100644
--- a/source/blender/makesrna/intern/rna_object.c
+++ b/source/blender/makesrna/intern/rna_object.c
@@ -1828,8 +1828,19 @@ static void rna_Object_boundbox_get(PointerRNA *ptr, float *values)
   }
 }
 
-static bDeformGroup *rna_Object_vgroup_new(Object *ob, Main *bmain, const char *name)
-{
+static bDeformGroup *rna_Object_vgroup_new(Object *ob,
+                                           Main *bmain,
+                                           ReportList *reports,
+                                           const char *name)
+{
+  if (!OB_TYPE_SUPPORT_VGROUP(ob->type)) {
+    const char *ob_type_name = "Unknown";
+    RNA_enum_name_from_value(rna_enum_object_type_items, ob->type, &ob_type_name);
+    BKE_reportf(
+        reports, RPT_ERROR, "VertexGroups.new(): is not supported for '%s' objects", ob_type_name);
+    return NULL;
+  }
+
   bDeformGroup *defgroup = BKE_object_defgroup_add_name(ob, name);
 
   DEG_relations_tag_update(bmain);
@@ -2489,7 +2500,7 @@ static void rna_def_object_vertex_groups(BlenderRNA *brna, PropertyRNA *cprop)
 
   /* vertex groups */ /* add_vertex_group */
   func = RNA_def_function(srna, "new", "rna_Object_vgroup_new");
-  RNA_def_function_flag(func, FUNC_USE_MAIN);
+  RNA_def_function_flag(func, FUNC_USE_MAIN | FUNC_USE_REPORTS);
   RNA_def_function_ui_description(func, "Add vertex group to object");
   RNA_def_string(func, "name", "Group", 0, "", "Vertex group name"); /* optional */
   parm = RNA_def_pointer(func, "group", "VertexGroup", "", "New vertex group");



More information about the Bf-blender-cvs mailing list