- added RNA_struct_free_extension rather then having the funcs in each unregister...
authorCampbell Barton <ideasman42@gmail.com>
Sun, 16 Aug 2009 07:26:29 +0000 (07:26 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 16 Aug 2009 07:26:29 +0000 (07:26 +0000)
- use RNA_struct_blender_type_set to set the type to NULL before its freed

There is a memory error here when reloading scripts - ui_handler_panel_region, need to look into theis further.

source/blender/editors/interface/interface_panel.c
source/blender/makesrna/RNA_define.h
source/blender/makesrna/intern/rna_define.c
source/blender/makesrna/intern/rna_render.c
source/blender/makesrna/intern/rna_ui.c

index 846fbe7..efff5b8 100644 (file)
@@ -1247,7 +1247,7 @@ int ui_handler_panel_region(bContext *C, wmEvent *event)
 
                if(!pa || pa->paneltab!=NULL)
                        continue;
-               if(pa->type && pa->type->flag & PNL_NO_HEADER)
+               if(pa->type && pa->type->flag & PNL_NO_HEADER) // XXX - accessed freed panels when scripts reload, need to fix.
                        continue;
 
                if(block->minx <= mx && block->maxx >= mx)
index ae9eaba..33f5d71 100644 (file)
@@ -63,6 +63,7 @@ void RNA_def_struct_path_func(StructRNA *srna, const char *path);
 void RNA_def_struct_identifier(StructRNA *srna, const char *identifier);
 void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description);
 void RNA_def_struct_ui_icon(StructRNA *srna, int icon);
+void RNA_struct_free_extension(StructRNA *srna, ExtensionRNA *ext);
 void RNA_struct_free(BlenderRNA *brna, StructRNA *srna);
 
 /* Compact Property Definitions */
index ffbacde..0861d7d 100644 (file)
@@ -458,6 +458,15 @@ void RNA_define_verify_sdna(int verify)
        DefRNA.verify= verify;
 }
 
+void RNA_struct_free_extension(StructRNA *srna, ExtensionRNA *ext)
+{
+#ifdef RNA_RUNTIME
+       ext->free(ext->data);                   /* decref's the PyObject that the srna owns */
+       RNA_struct_blender_type_set(srna, NULL); /* this gets accessed again - XXX fixme */
+       RNA_struct_py_type_set(srna, NULL);     /* NULL the srna's value so RNA_struct_free wont complain of a leak */
+#endif 
+}
+
 void RNA_struct_free(BlenderRNA *brna, StructRNA *srna)
 {
 #ifdef RNA_RUNTIME
index 040284c..eaea62d 100644 (file)
@@ -106,9 +106,7 @@ static void rna_RenderEngine_unregister(const bContext *C, StructRNA *type)
        if(!et)
                return;
        
-       et->ext.free(et->ext.data);                     /* decref's the PyObject that the srna owns */
-       RNA_struct_py_type_set(type, NULL);     /* NULL the srna's value so RNA_struct_free wont complain of a leak */
-
+       RNA_struct_free_extension(type, &et->ext);
        BLI_freelinkN(&R_engines, et);
        RNA_struct_free(&BLENDER_RNA, type);
 }
index 5a33bcd..660dbb4 100644 (file)
@@ -138,8 +138,7 @@ static void rna_Panel_unregister(const bContext *C, StructRNA *type)
        if(!(art=region_type_find(NULL, pt->space_type, pt->region_type)))
                return;
        
-       pt->ext.free(pt->ext.data);                     /* decref's the PyObject that the srna owns */
-       RNA_struct_py_type_set(type, NULL);     /* NULL the srna's value so RNA_struct_free wont complain of a leak */
+       RNA_struct_free_extension(type, &pt->ext);
 
        BLI_freelinkN(&art->paneltypes, pt);
        RNA_struct_free(&BLENDER_RNA, type);
@@ -236,8 +235,7 @@ static void rna_Header_unregister(const bContext *C, StructRNA *type)
        if(!(art=region_type_find(NULL, ht->space_type, RGN_TYPE_HEADER)))
                return;
        
-       ht->ext.free(ht->ext.data);                     /* decref's the PyObject that the srna owns */
-       RNA_struct_py_type_set(type, NULL);     /* NULL the srna's value so RNA_struct_free wont complain of a leak */
+       RNA_struct_free_extension(type, &ht->ext);
 
        BLI_freelinkN(&art->headertypes, ht);
        RNA_struct_free(&BLENDER_RNA, type);
@@ -353,8 +351,7 @@ static void rna_Menu_unregister(const bContext *C, StructRNA *type)
        if(!(art=region_type_find(NULL, mt->space_type, RGN_TYPE_HEADER)))
                return;
        
-       mt->ext.free(mt->ext.data);                     /* decref's the PyObject that the srna owns */
-       RNA_struct_py_type_set(type, NULL);     /* NULL the srna's value so RNA_struct_free wont complain of a leak */
+       RNA_struct_free_extension(type, &mt->ext);
 
        BLI_freelinkN(&art->menutypes, mt);
        RNA_struct_free(&BLENDER_RNA, type);