From f93360b3bb29e27b6345194172017f32c1df6868 Mon Sep 17 00:00:00 2001 From: Philipp Oeser Date: Sun, 26 May 2024 11:32:50 +0200 Subject: [PATCH] Fix: dont allow image operations on non-editable images Non-editable is mostly linked (besides some incoming exception for the Brush Asset project). If the Image is linked but not packed, conceptually it does not really make a difference (edits for a linked vs local image would still end up in the same external file when saved). However when it is linked and packed we are running into Undo crashes (#122131). Also the image remains linked, so data remains to be read/loaded from the packed version from the library (so any edits are lost). For consistency, disallow image operations for all non-editable images. ref. #122131 ref. #122033 Pull Request: https://projects.blender.org/blender/blender/pulls/122209 --- source/blender/editors/space_image/image_ops.cc | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/source/blender/editors/space_image/image_ops.cc b/source/blender/editors/space_image/image_ops.cc index 7bc016edcd8..13138853b19 100644 --- a/source/blender/editors/space_image/image_ops.cc +++ b/source/blender/editors/space_image/image_ops.cc @@ -236,9 +236,15 @@ static bool image_from_context_has_data_poll(bContext *C) /** * Use this when the image buffer is accessing the active tile without the image user. */ -static bool image_from_context_has_data_poll_active_tile(bContext *C) +static bool image_from_context_editable_has_data_poll_active_tile(bContext *C) { Image *ima = image_from_context(C); + + if (!ID_IS_EDITABLE(&ima->id)) { + CTX_wm_operator_poll_msg_set(C, "Image is not editable"); + return false; + } + ImageUser iuser = image_user_from_context_and_active_tile(C, ima); return BKE_image_has_ibuf(ima, &iuser); @@ -2841,7 +2847,7 @@ void IMAGE_OT_flip(wmOperatorType *ot) /* api callbacks */ ot->exec = image_flip_exec; - ot->poll = image_from_context_has_data_poll_active_tile; + ot->poll = image_from_context_editable_has_data_poll_active_tile; /* properties */ PropertyRNA *prop; @@ -2922,7 +2928,7 @@ void IMAGE_OT_rotate_orthogonal(wmOperatorType *ot) /* api callbacks */ ot->exec = image_rotate_orthogonal_exec; - ot->poll = image_from_context_has_data_poll_active_tile; + ot->poll = image_from_context_editable_has_data_poll_active_tile; /* properties */ PropertyRNA *prop; @@ -3168,7 +3174,7 @@ void IMAGE_OT_invert(wmOperatorType *ot) /* api callbacks */ ot->exec = image_invert_exec; - ot->poll = image_from_context_has_data_poll_active_tile; + ot->poll = image_from_context_editable_has_data_poll_active_tile; /* properties */ prop = RNA_def_boolean(ot->srna, "invert_r", false, "Red", "Invert red channel"); @@ -3260,7 +3266,7 @@ void IMAGE_OT_resize(wmOperatorType *ot) /* api callbacks */ ot->invoke = image_scale_invoke; ot->exec = image_scale_exec; - ot->poll = image_from_context_has_data_poll_active_tile; + ot->poll = image_from_context_editable_has_data_poll_active_tile; /* properties */ RNA_def_int_vector(ot->srna, "size", 2, nullptr, 1, INT_MAX, "Size", "", 1, SHRT_MAX);