Fix #112083: Loop cut requires GL only in interactive mode

Loop cut operator should only require OpenGL in interactive mode, this
makes it possible to run background python script calling the operator.

Thanks for the help from Campbell Barton (@ideasman42)

Pull Request: https://projects.blender.org/blender/blender/pulls/112121
This commit is contained in:
ChengduLittleA 2023-09-18 15:45:16 +02:00 committed by YimingWu
parent 57990ec3fc
commit 34877ec38b
1 changed files with 10 additions and 3 deletions

View File

@ -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;