diff options
author | Hans Goudey <h.goudey@me.com> | 2021-07-16 19:23:55 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-07-16 19:23:55 +0300 |
commit | c4df8ac1a40c7a98a4244c7c14e19791b1e1e99f (patch) | |
tree | 84a58251d70c913d5bbee1571736a9ffe1ad5a48 /source/blender/makesrna/intern/rna_object.c | |
parent | 6025897cd6023babfcffed33a6be3ce0bbd127b9 (diff) |
Fix T89899: Crashes when accessing vertex groups from objects
We need to be more strict about trying to retrieve a list of vertex group
names from objects now, as only three object types support them.
This commit adds a check for vertex group support in a few places, the
data transfer operator/modifier, copying vertex groups to selected
objects, and the vertex group remove and clear functions.
Differential Revision: https://developer.blender.org/D11947
Diffstat (limited to 'source/blender/makesrna/intern/rna_object.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_object.c | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c index e110459eeea..ed681291e29 100644 --- a/source/blender/makesrna/intern/rna_object.c +++ b/source/blender/makesrna/intern/rna_object.c @@ -1997,16 +1997,25 @@ static void rna_Object_boundbox_get(PointerRNA *ptr, float *values) } } +static bool check_object_vgroup_support_and_warn(const Object *ob, + const char *op_name, + ReportList *reports) +{ + if (!BKE_object_supports_vertex_groups(ob)) { + 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, "%s is not supported for '%s' objects", op_name, ob_type_name); + return false; + } + return true; +} + 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); + if (!check_object_vgroup_support_and_warn(ob, "VertexGroups.new()", reports)) { return NULL; } @@ -2023,6 +2032,10 @@ static void rna_Object_vgroup_remove(Object *ob, ReportList *reports, PointerRNA *defgroup_ptr) { + if (!check_object_vgroup_support_and_warn(ob, "VertexGroups.remove()", reports)) { + return; + } + bDeformGroup *defgroup = defgroup_ptr->data; ListBase *defbase = BKE_object_defgroup_list_mutable(ob); @@ -2042,8 +2055,12 @@ static void rna_Object_vgroup_remove(Object *ob, WM_main_add_notifier(NC_OBJECT | ND_DRAW, ob); } -static void rna_Object_vgroup_clear(Object *ob, Main *bmain) +static void rna_Object_vgroup_clear(Object *ob, Main *bmain, ReportList *reports) { + if (!check_object_vgroup_support_and_warn(ob, "VertexGroups.clear()", reports)) { + return; + } + BKE_object_defgroup_remove_all(ob); DEG_relations_tag_update(bmain); @@ -2777,7 +2794,7 @@ static void rna_def_object_vertex_groups(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_parameter_clear_flags(parm, PROP_THICK_WRAP, 0); func = RNA_def_function(srna, "clear", "rna_Object_vgroup_clear"); - 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, "Delete all vertex groups from object"); } |