diff --git a/source/blender/editors/mesh/editmesh_loopcut.cc b/source/blender/editors/mesh/editmesh_loopcut.cc index 327108c23a6..a62cb136e40 100644 --- a/source/blender/editors/mesh/editmesh_loopcut.cc +++ b/source/blender/editors/mesh/editmesh_loopcut.cc @@ -374,7 +374,11 @@ static void loopcut_mouse_move(RingSelOpData *lcd, const int previewlines) /* called by both init() and exec() */ static int loopcut_init(bContext *C, wmOperator *op, const wmEvent *event) { - const bool is_interactive = (event != nullptr); + /* Check whether both `rv3d` and `event` is present, this way we allow the loopcut operator to + * run non-interactively no matter whether the graphical UI is present or not (e.g. from scripts + * with UI running, or entirely in the background with `blender -b`). */ + RegionView3D *rv3d = CTX_wm_region_view3d(C); + const bool is_interactive = (rv3d != nullptr) && (event != nullptr); /* Use for redo - intentionally wrap int to uint. */ struct { @@ -404,7 +408,9 @@ static int loopcut_init(bContext *C, wmOperator *op, const wmEvent *event) } } - view3d_operator_needs_opengl(C); + if (is_interactive) { + view3d_operator_needs_opengl(C); + } /* for re-execution, check edge index is in range before we setup ringsel */ bool ok = true; @@ -737,7 +743,8 @@ void MESH_OT_loopcut(wmOperatorType *ot) ot->exec = loopcut_exec; ot->modal = loopcut_modal; ot->cancel = ringcut_cancel; - ot->poll = ED_operator_editmesh_region_view3d; + /* Note the #RegionView3D is needed for interactive use, the operator must check this. */ + ot->poll = ED_operator_editmesh; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;