From 53f0c2c14d8d97d90c5fc16bb386fa79f2d56b0a Mon Sep 17 00:00:00 2001 From: Christoph Lendenfeld Date: Fri, 16 Aug 2024 12:41:53 +0200 Subject: [PATCH] Fix: Wrong message in driver for disabled execution This backports the following 2 commits to 4.2 1a8053939bd79e0bd7a896ae0f3b1b9195ecb142 e2bc41598d8e66f0804a255e17001fff0aa8c92b These two fix an issue where the driver stated it is invalid, while in fact it couldn't execute due to python being blocked. Original report: #106372 Pull Request: https://projects.blender.org/blender/blender/pulls/126088 --- source/blender/blenkernel/intern/fcurve.cc | 2 +- .../blender/editors/space_graph/graph_buttons.cc | 15 +++++++-------- source/blender/makesdna/DNA_anim_types.h | 3 ++- source/blender/python/intern/bpy_driver.cc | 3 +++ 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/source/blender/blenkernel/intern/fcurve.cc b/source/blender/blenkernel/intern/fcurve.cc index 81dcd451ebe..0c3a55b8281 100644 --- a/source/blender/blenkernel/intern/fcurve.cc +++ b/source/blender/blenkernel/intern/fcurve.cc @@ -2701,7 +2701,7 @@ void BKE_fcurve_blend_read_data(BlendDataReader *reader, FCurve *fcu) /* Give the driver a fresh chance - the operating environment may be different now * (addons, etc. may be different) so the driver namespace may be sane now #32155. */ - driver->flag &= ~DRIVER_FLAG_INVALID; + driver->flag &= ~(DRIVER_FLAG_INVALID | DRIVER_FLAG_PYTHON_BLOCKED); /* relink variables, targets and their paths */ BLO_read_struct_list(reader, DriverVar, &driver->variables); diff --git a/source/blender/editors/space_graph/graph_buttons.cc b/source/blender/editors/space_graph/graph_buttons.cc index cf78b2cbef7..5cc19cbcb7b 100644 --- a/source/blender/editors/space_graph/graph_buttons.cc +++ b/source/blender/editors/space_graph/graph_buttons.cc @@ -1033,17 +1033,16 @@ static void graph_draw_driver_settings_panel(uiLayout *layout, col = uiLayoutColumn(layout, true); block = uiLayoutGetBlock(col); - if (driver->flag & DRIVER_FLAG_INVALID) { + if (driver->flag & DRIVER_FLAG_PYTHON_BLOCKED) { + /* TODO: Add button to enable? */ + uiItemL(col, RPT_("Python restricted for security"), ICON_ERROR); + uiItemL(col, RPT_("Slow Python expression"), ICON_INFO); + } + else if (driver->flag & DRIVER_FLAG_INVALID) { uiItemL(col, RPT_("ERROR: Invalid Python expression"), ICON_CANCEL); } else if (!BKE_driver_has_simple_expression(driver)) { - if ((G.f & G_FLAG_SCRIPT_AUTOEXEC) == 0) { - /* TODO: Add button to enable? */ - uiItemL(col, RPT_("Python restricted for security"), ICON_ERROR); - } - else { - uiItemL(col, RPT_("Slow Python expression"), ICON_INFO); - } + uiItemL(col, RPT_("Slow Python expression"), ICON_INFO); } /* Explicit bpy-references are evil. Warn about these to prevent errors */ diff --git a/source/blender/makesdna/DNA_anim_types.h b/source/blender/makesdna/DNA_anim_types.h index 2f0de3e4cb3..2b4f094d617 100644 --- a/source/blender/makesdna/DNA_anim_types.h +++ b/source/blender/makesdna/DNA_anim_types.h @@ -570,7 +570,8 @@ typedef enum eDriver_Flags { DRIVER_FLAG_RECOMPILE = (1 << 3), /** The names are cached so they don't need have python unicode versions created each time */ DRIVER_FLAG_RENAMEVAR = (1 << 4), - // DRIVER_FLAG_UNUSED_5 = (1 << 5), + /* Set if the driver cannot run because it uses Python which isn't allowed to execute. */ + DRIVER_FLAG_PYTHON_BLOCKED = (1 << 5), /** Include 'self' in the drivers namespace. */ DRIVER_FLAG_USE_SELF = (1 << 6), } eDriver_Flags; diff --git a/source/blender/python/intern/bpy_driver.cc b/source/blender/python/intern/bpy_driver.cc index f4b0e29ddb5..ea56bfcbbe6 100644 --- a/source/blender/python/intern/bpy_driver.cc +++ b/source/blender/python/intern/bpy_driver.cc @@ -527,6 +527,7 @@ float BPY_driver_exec(PathResolvedRNA *anim_rna, printf("skipping driver '%s', automatic scripts are disabled\n", expr); } + driver_orig->flag |= DRIVER_FLAG_PYTHON_BLOCKED; return 0.0f; } #else @@ -581,6 +582,7 @@ float BPY_driver_exec(PathResolvedRNA *anim_rna, /* Maybe this can be removed but for now best keep until were sure. */ driver_orig->flag |= DRIVER_FLAG_RENAMEVAR; + driver_orig->flag &= ~DRIVER_FLAG_PYTHON_BLOCKED; #ifdef USE_BYTECODE_WHITELIST is_recompile = true; #endif @@ -689,6 +691,7 @@ float BPY_driver_exec(PathResolvedRNA *anim_rna, Py_DECREF(expr_code); expr_code = nullptr; PyTuple_SET_ITEM(((PyObject *)driver_orig->expr_comp), 0, nullptr); + driver_orig->flag |= DRIVER_FLAG_PYTHON_BLOCKED; } } }