Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2022-06-14 17:17:54 +0300
committerJulian Eisel <julian@blender.org>2022-06-14 17:21:12 +0300
commit67254ea37cb4d20e14666c679e439230732a3fb6 (patch)
tree4dc765aa68fa0de691c0a368bbdc83c33645910c /source/blender/editors/space_outliner
parente772087ed664ffcc230850837558415cc9015f71 (diff)
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.
Diffstat (limited to 'source/blender/editors/space_outliner')
-rw-r--r--source/blender/editors/space_outliner/outliner_tools.cc18
1 files changed, 16 insertions, 2 deletions
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;
}