From 026ac2492232fac4fb7350ff210ba34b353a84e2 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 23 Jul 2010 01:43:30 +0000 Subject: [#22488] Reloading scripts causes crash F8 key enabled again, useful for script UI development. - keying set freeing wasnt freeing from all scenes and the builtin list. - PointerProperty() cant refer to a removed python srna type (fixed in rigify and netrender). - Added a check for freeing a type used by a PointerProperty but its very slow, makes reloading take ~10sec. Only enabled this in debug mode for now. Netrender register() function isnt re-registering the property, probably because the module is cached by python and not re-run. --- release/scripts/io/netrender/__init__.py | 3 + .../scripts/ui/properties_data_armature_rigify.py | 1 + source/blender/editors/animation/keyingsets.c | 11 +++- source/blender/editors/space_script/script_edit.c | 10 +--- source/blender/python/generic/mathutils.h | 13 ----- source/blender/python/intern/bpy_rna.c | 64 +++++++++++++++++++++- source/blender/python/intern/bpy_rna.h | 4 -- 7 files changed, 77 insertions(+), 29 deletions(-) diff --git a/release/scripts/io/netrender/__init__.py b/release/scripts/io/netrender/__init__.py index f5f104d6d92..43f3094e628 100644 --- a/release/scripts/io/netrender/__init__.py +++ b/release/scripts/io/netrender/__init__.py @@ -42,6 +42,9 @@ def register(): def unregister(): import bpy + + bpy.types.Scene.RemoveProperty("network_render") + bpy.types.unregister(ui.NetRenderJob) bpy.types.unregister(ui.NetRenderSettings) bpy.types.unregister(ui.NetRenderSlave) diff --git a/release/scripts/ui/properties_data_armature_rigify.py b/release/scripts/ui/properties_data_armature_rigify.py index 43021858f9f..193ff390b1e 100644 --- a/release/scripts/ui/properties_data_armature_rigify.py +++ b/release/scripts/ui/properties_data_armature_rigify.py @@ -360,6 +360,7 @@ def register(): def unregister(): + bpy.types.Scene.RemoveProperty("pose_templates") unregister = bpy.types.unregister for cls in classes: unregister(cls) diff --git a/source/blender/editors/animation/keyingsets.c b/source/blender/editors/animation/keyingsets.c index 1c06266a148..301111d22fd 100644 --- a/source/blender/editors/animation/keyingsets.c +++ b/source/blender/editors/animation/keyingsets.c @@ -43,6 +43,7 @@ #include "DNA_constraint_types.h" #include "DNA_scene_types.h" +#include "BKE_main.h" #include "BKE_animsys.h" #include "BKE_action.h" #include "BKE_context.h" @@ -589,7 +590,7 @@ void ANIM_keyingset_info_register (const bContext *C, KeyingSetInfo *ksi) /* Remove the given KeyingSetInfo from the list of type infos, and also remove the builtin set if appropriate */ void ANIM_keyingset_info_unregister (const bContext *C, KeyingSetInfo *ksi) { - Scene *scene = CTX_data_scene(C); + Main *bmain= CTX_data_main(C); KeyingSet *ks, *ksn; /* find relevant builtin KeyingSets which use this, and remove them */ @@ -600,8 +601,14 @@ void ANIM_keyingset_info_unregister (const bContext *C, KeyingSetInfo *ksi) /* remove if matching typeinfo name */ if (strcmp(ks->typeinfo, ksi->idname) == 0) { + Scene *scene; BKE_keyingset_free(ks); - BLI_freelinkN(&scene->keyingsets, ks); + BLI_remlink(&builtin_keyingsets, ks); + + for(scene= bmain->scene.first; scene; scene= scene->id.next) + BLI_remlink_safe(&scene->keyingsets, ks); + + MEM_freeN(ks); } } diff --git a/source/blender/editors/space_script/script_edit.c b/source/blender/editors/space_script/script_edit.c index 71b37e514d7..6f41f235b7b 100644 --- a/source/blender/editors/space_script/script_edit.c +++ b/source/blender/editors/space_script/script_edit.c @@ -90,13 +90,9 @@ static int script_reload_exec(bContext *C, wmOperator *op) #ifndef DISABLE_PYTHON /* TODO, this crashes on netrender and keying sets, need to look into why * disable for now unless running in debug mode */ - if(G.f & G_DEBUG) { - BPY_eval_string(C, "__import__('bpy').utils.load_scripts(reload_scripts=True)"); - } - else { - BKE_reportf(op->reports, RPT_ERROR, "reloading is currently unstable, only operates in debug mode.\n"); - return OPERATOR_CANCELLED; - } + WM_cursor_wait(1); + BPY_eval_string(C, "__import__('bpy').utils.load_scripts(reload_scripts=True)"); + WM_cursor_wait(0); return OPERATOR_FINISHED; #endif return OPERATOR_CANCELLED; diff --git a/source/blender/python/generic/mathutils.h b/source/blender/python/generic/mathutils.h index a86d9286c28..7b83d35ff1e 100644 --- a/source/blender/python/generic/mathutils.h +++ b/source/blender/python/generic/mathutils.h @@ -74,19 +74,6 @@ int EXPP_VectorsAreEqual(float *vecA, float *vecB, int size, int floatSteps); #define Py_NEW 1 #define Py_WRAP 2 - -/* Mathutils is used by the BGE and Blender so have to define - * some things here for luddite mac users of py2.3 */ -#ifndef Py_RETURN_NONE -#define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None -#endif -#ifndef Py_RETURN_FALSE -#define Py_RETURN_FALSE return Py_INCREF(Py_False), Py_False -#endif -#ifndef Py_RETURN_TRUE -#define Py_RETURN_TRUE return Py_INCREF(Py_True), Py_True -#endif - typedef struct Mathutils_Callback Mathutils_Callback; typedef int (*BaseMathCheckFunc)(BaseMathObject *); /* checks the user is still valid */ diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 0a7fe81ed08..69caee898a0 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -4163,6 +4163,9 @@ static PyObject *pyrna_basetype_getattro( BPy_BaseTypeRNA *self, PyObject *pynam } static PyObject *pyrna_basetype_dir(BPy_BaseTypeRNA *self); +static PyObject *pyrna_basetype_register(PyObject *self, PyObject *py_class); +static PyObject *pyrna_basetype_unregister(PyObject *self, PyObject *py_class); + static struct PyMethodDef pyrna_basetype_methods[] = { {"__dir__", (PyCFunction)pyrna_basetype_dir, METH_NOARGS, ""}, {"register", (PyCFunction)pyrna_basetype_register, METH_O, ""}, @@ -4760,7 +4763,7 @@ void pyrna_free_types(void) * - Should still be fixed - Campbell * */ -PyObject *pyrna_basetype_register(PyObject *self, PyObject *py_class) +static PyObject *pyrna_basetype_register(PyObject *self, PyObject *py_class) { bContext *C= NULL; ReportList reports; @@ -4836,14 +4839,41 @@ PyObject *pyrna_basetype_register(PyObject *self, PyObject *py_class) Py_RETURN_NONE; } -PyObject *pyrna_basetype_unregister(PyObject *self, PyObject *py_class) + +static int pyrna_srna_contains_pointer_prop_srna(StructRNA *srna_props, StructRNA *srna, const char **prop_identifier) +{ + PointerRNA tptr; + PropertyRNA *iterprop; + RNA_pointer_create(NULL, &RNA_Struct, srna_props, &tptr); + + iterprop= RNA_struct_find_property(&tptr, "properties"); + + RNA_PROP_BEGIN(&tptr, itemptr, iterprop) { + PropertyRNA *prop= itemptr.data; + if(RNA_property_type(prop) == PROP_POINTER) { + if (strcmp(RNA_property_identifier(prop), "rna_type") == 0) { + /* pass */ + } + else if(RNA_property_pointer_type(&tptr, prop) == srna) { + *prop_identifier= RNA_property_identifier(prop); + return 1; + } + } + } + RNA_PROP_END; + + return 0; +} + +static PyObject *pyrna_basetype_unregister(PyObject *self, PyObject *py_class) { bContext *C= NULL; StructUnregisterFunc unreg; StructRNA *srna; /*if(PyDict_GetItemString(((PyTypeObject*)py_class)->tp_dict, "bl_rna")==NULL) { - PyErr_SetString(PyExc_ValueError, "bpy.types.unregister(): not a registered as a subclass."); + PWM_cursor_wait(0); +yErr_SetString(PyExc_ValueError, "bpy.types.unregister(): not a registered as a subclass."); return NULL; }*/ @@ -4859,6 +4889,34 @@ PyObject *pyrna_basetype_unregister(PyObject *self, PyObject *py_class) return NULL; } + /* should happen all the time but very slow */ + if(G.f & G_DEBUG) { + /* remove all properties using this class */ + StructRNA *srna_iter; + PointerRNA ptr_rna; + PropertyRNA *prop_rna; + const char *prop_identifier= NULL; + + RNA_blender_rna_pointer_create(&ptr_rna); + prop_rna = RNA_struct_find_property(&ptr_rna, "structs"); + + + + /* loop over all structs */ + RNA_PROP_BEGIN(&ptr_rna, itemptr, prop_rna) { + srna_iter = itemptr.data; + if(pyrna_srna_contains_pointer_prop_srna(srna_iter, srna, &prop_identifier)) { + break; + } + } + RNA_PROP_END; + + if(prop_identifier) { + PyErr_Format(PyExc_SystemError, "bpy.types.unregister(...): Cant unregister %s because %s.%s pointer property is using this.", RNA_struct_identifier(srna), RNA_struct_identifier(srna_iter), prop_identifier); + return NULL; + } + } + /* get the context, so register callback can do necessary refreshes */ C= BPy_GetContext(); diff --git a/source/blender/python/intern/bpy_rna.h b/source/blender/python/intern/bpy_rna.h index 9892ed6989b..bd9838a76d4 100644 --- a/source/blender/python/intern/bpy_rna.h +++ b/source/blender/python/intern/bpy_rna.h @@ -86,10 +86,6 @@ int pyrna_set_to_enum_bitfield(EnumPropertyItem *items, PyObject *value, int *r_ int pyrna_enum_value_from_id(EnumPropertyItem *item, const char *identifier, int *value, const char *error_prefix); -/* function for registering types */ -PyObject *pyrna_basetype_register(PyObject *self, PyObject *args); -PyObject *pyrna_basetype_unregister(PyObject *self, PyObject *args); - int pyrna_deferred_register_props(struct StructRNA *srna, PyObject *class_dict); /* called before stopping python */ -- cgit v1.2.3