From 67254ea37cb4d20e14666c679e439230732a3fb6 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Tue, 14 Jun 2022 16:17:54 +0200 Subject: Outliner: Sanitize material unlinking callback, report errors The callback would just assume that it's only called on materials, which may in fact not be the case. It could also be called for other ID types and layer collections (see `outliner_do_libdata_operation()`). Properly check this now. Also avoid faling silently when the object or object-data to unlink from couldn't be determined. Report this to the user. Operators that just do nothing are confusing. --- .../blender/editors/space_outliner/outliner_tools.cc | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'source/blender/editors/space_outliner') diff --git a/source/blender/editors/space_outliner/outliner_tools.cc b/source/blender/editors/space_outliner/outliner_tools.cc index 5c7b0732beb..ec19e8d5e5b 100644 --- a/source/blender/editors/space_outliner/outliner_tools.cc +++ b/source/blender/editors/space_outliner/outliner_tools.cc @@ -222,16 +222,30 @@ static void unlink_action_fn(bContext *C, } static void unlink_material_fn(bContext *UNUSED(C), - ReportList *UNUSED(reports), + ReportList *reports, Scene *UNUSED(scene), TreeElement *te, TreeStoreElem *tsep, - TreeStoreElem *UNUSED(tselem), + TreeStoreElem *tselem, void *UNUSED(user_data)) { + const bool te_is_material = TSE_IS_REAL_ID(tselem) && (GS(tselem->id->name) == ID_MA); + + if (!te_is_material) { + /* Just fail silently. Another element may be selected that is a material, we don't want to + * confuse users with an error in that case. */ + return; + } + if (!tsep || !TSE_IS_REAL_ID(tsep)) { /* Valid case, no parent element of the material or it is not an ID (could be a #TSE_ID_BASE * for example) so there's no data to unlink from. */ + BKE_reportf(reports, + RPT_WARNING, + "Cannot unlink material '%s'. It's not clear which object or object-data it " + "should be unlinked from, there's no object or object-data as parent in the " + "Outliner tree", + tselem->id->name + 2); return; } -- cgit v1.2.3