fix for own but in recent driver optimization [#20580] Driver Crasher rev [25763]
authorCampbell Barton <ideasman42@gmail.com>
Wed, 6 Jan 2010 22:42:13 +0000 (22:42 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 6 Jan 2010 22:42:13 +0000 (22:42 +0000)
recalculate names when needed

source/blender/blenkernel/intern/fcurve.c
source/blender/makesdna/DNA_anim_types.h
source/blender/makesrna/intern/rna_fcurve.c
source/blender/python/intern/bpy_driver.c

index 67bee90e91cb54fbaaea71180eadffb87984fcd1..e86cfce6fd98fc119757ac110926a19bf7de5bac 100644 (file)
@@ -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;
 }
index 5b0dfbdd574a727820e43b6a8a70d655ded3308e..958add428a4a7a93cec0445d173d59fe31f10542 100644 (file)
@@ -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 -------------------------------------- */
index 1fa731f512baeb220aa25f4ff2036558504bf1e4..b6b05eb48964bd2dca5310db475e6c19f7cec21a 100644 (file)
@@ -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);
index 6f2f7a6f3b3c68055b2201e2e63965116def682c..f80d79d9a2a7d4ad0d45c4556ca88377159e0da8 100644 (file)
@@ -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, "<bpy driver>", 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);
        }