diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c index 67bee90e91c..e86cfce6fd9 100644 --- a/source/blender/blenkernel/intern/fcurve.c +++ b/source/blender/blenkernel/intern/fcurve.c @@ -1097,6 +1097,12 @@ void driver_free_variable (ChannelDriver *driver, DriverVar *dvar) BLI_freelinkN(&driver->variables, dvar); else MEM_freeN(dvar); + +#ifndef DISABLE_PYTHON + /* since driver variables are cached, the expression needs re-compiling too */ + if(driver->type==DRIVER_TYPE_PYTHON) + driver->flag |= DRIVER_FLAG_RENAMEVAR; +#endif } /* Change the type of driver variable */ @@ -1149,6 +1155,12 @@ DriverVar *driver_add_new_variable (ChannelDriver *driver) /* set the default type to 'single prop' */ driver_change_variable_type(dvar, DVAR_TYPE_SINGLE_PROP); +#ifndef DISABLE_PYTHON + /* since driver variables are cached, the expression needs re-compiling too */ + if(driver->type==DRIVER_TYPE_PYTHON) + driver->flag |= DRIVER_FLAG_RENAMEVAR; +#endif + /* return the target */ return dvar; } diff --git a/source/blender/makesdna/DNA_anim_types.h b/source/blender/makesdna/DNA_anim_types.h index 5b0dfbdd574..958add428a4 100644 --- a/source/blender/makesdna/DNA_anim_types.h +++ b/source/blender/makesdna/DNA_anim_types.h @@ -371,7 +371,9 @@ typedef enum eDriver_Flags { // TODO: this needs to be implemented at some stage or left out... //DRIVER_FLAG_LAYERING = (1<<2), /* use when the expression needs to be recompiled */ - DRIVER_FLAG_RECOMPILE = (1<<3), + DRIVER_FLAG_RECOMPILE = (1<<3), + /* the names are cached so they dont need have python unicode versions created each time */ + DRIVER_FLAG_RENAMEVAR = (1<<4), } eDriver_Flags; /* F-Curves -------------------------------------- */ diff --git a/source/blender/makesrna/intern/rna_fcurve.c b/source/blender/makesrna/intern/rna_fcurve.c index 1fa731f512b..b6b05eb4896 100644 --- a/source/blender/makesrna/intern/rna_fcurve.c +++ b/source/blender/makesrna/intern/rna_fcurve.c @@ -129,6 +129,15 @@ static void rna_DriverTarget_update_data(Main *bmain, Scene *scene, PointerRNA * } } +static void rna_DriverTarget_update_name(Main *bmain, Scene *scene, PointerRNA *ptr) +{ + ChannelDriver *driver= ptr->data; + rna_DriverTarget_update_data(bmain, scene, ptr); + + driver->flag |= DRIVER_FLAG_RENAMEVAR; + +} + /* ----------- */ static StructRNA *rna_DriverTarget_id_typef(PointerRNA *ptr) @@ -764,7 +773,7 @@ static void rna_def_drivervar(BlenderRNA *brna) prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); RNA_def_struct_name_property(srna, prop); RNA_def_property_ui_text(prop, "Name", "Name to use in scripted expressions/functions. (No spaces or dots are allowed. Also, must not start with a symbol or digit)"); - RNA_def_property_update(prop, 0, "rna_DriverTarget_update_data"); // XXX + RNA_def_property_update(prop, 0, "rna_DriverTarget_update_name"); // XXX /* Enums */ prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE); diff --git a/source/blender/python/intern/bpy_driver.c b/source/blender/python/intern/bpy_driver.c index 6f2f7a6f3b3..f80d79d9a2a 100644 --- a/source/blender/python/intern/bpy_driver.c +++ b/source/blender/python/intern/bpy_driver.c @@ -177,14 +177,29 @@ float BPY_pydriver_eval (ChannelDriver *driver) } } + if(driver->expr_comp==NULL) + driver->flag |= DRIVER_FLAG_RECOMPILE; + /* compile the expression first if it hasn't been compiled or needs to be rebuilt */ - if((driver->flag & DRIVER_FLAG_RECOMPILE) || (driver->expr_comp==NULL)) { + if(driver->flag & DRIVER_FLAG_RECOMPILE) { Py_XDECREF(driver->expr_comp); driver->expr_comp= PyTuple_New(2); expr_code= Py_CompileString(expr, "", Py_eval_input); PyTuple_SET_ITEM(((PyObject *)driver->expr_comp), 0, expr_code); + driver->flag &= ~DRIVER_FLAG_RECOMPILE; + driver->flag |= DRIVER_FLAG_RENAMEVAR; /* maybe this can be removed but for now best keep until were sure */ + } + else { + expr_code= PyTuple_GET_ITEM(((PyObject *)driver->expr_comp), 0); + } + + if(driver->flag & DRIVER_FLAG_RENAMEVAR) { + /* may not be set */ + expr_vars= PyTuple_GET_ITEM(((PyObject *)driver->expr_comp), 1); + Py_XDECREF(expr_vars); + /* intern the arg names so creating the namespace for every run is faster */ expr_vars= PyTuple_New(BLI_countlist(&driver->variables)); PyTuple_SET_ITEM(((PyObject *)driver->expr_comp), 1, expr_vars); @@ -192,11 +207,8 @@ float BPY_pydriver_eval (ChannelDriver *driver) for (dvar= driver->variables.first, i=0; dvar; dvar= dvar->next) { PyTuple_SET_ITEM(expr_vars, i++, PyUnicode_InternFromString(dvar->name)); } - - driver->flag &= ~DRIVER_FLAG_RECOMPILE; } else { - expr_code= PyTuple_GET_ITEM(((PyObject *)driver->expr_comp), 0); expr_vars= PyTuple_GET_ITEM(((PyObject *)driver->expr_comp), 1); }