From 8d9bf47ba6edc770afd70d77f649d06dc1de649e Mon Sep 17 00:00:00 2001 From: Sean Kim Date: Thu, 5 Dec 2024 22:48:20 +0100 Subject: [PATCH] Sculpt: Prevent entering mode when object is invisible This is already prevented in the UI in both the top left mode selector and the pie menu, this commit adds an actual check to avoid being put into an invalid state by another operator or script. Pull Request: https://projects.blender.org/blender/blender/pulls/130769 --- source/blender/editors/sculpt_paint/sculpt_ops.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/source/blender/editors/sculpt_paint/sculpt_ops.cc b/source/blender/editors/sculpt_paint/sculpt_ops.cc index 6e2781df175..d803c27c01d 100644 --- a/source/blender/editors/sculpt_paint/sculpt_ops.cc +++ b/source/blender/editors/sculpt_paint/sculpt_ops.cc @@ -549,6 +549,16 @@ static int sculpt_mode_toggle_exec(bContext *C, wmOperator *op) if (!object::mode_compat_set(C, &ob, eObjectMode(mode_flag), op->reports)) { return OPERATOR_CANCELLED; } + + /* Being in sculpt mode on an invisible object is a confusing state; while switching the + * visibility of the current object shouldn't inherently change the mode, we prevent entering + * sculpt mode on an object that is already invisible to better align with how the mode toggle + * works currently. */ + const View3D *v3d = CTX_wm_view3d(C); + const Base *base = CTX_data_active_base(C); + if (!BKE_base_is_visible(v3d, base)) { + return OPERATOR_CANCELLED; + } } if (is_mode_set) {