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
This commit is contained in:
Sean Kim
2024-12-05 22:48:20 +01:00
committed by Sean Kim
parent 35c393acd6
commit 8d9bf47ba6

View File

@@ -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) {