avoid having dangling panel pointers in the interface, unregistering addons could...
authorCampbell Barton <ideasman42@gmail.com>
Wed, 9 Jan 2013 06:00:33 +0000 (06:00 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 9 Jan 2013 06:00:33 +0000 (06:00 +0000)
source/blender/editors/include/UI_interface.h
source/blender/editors/interface/interface_panel.c
source/blender/makesrna/intern/rna_ui.c

index 080367c43250215d744938b085c4bbaa31770d6c..16b5526ca26a4d1cec4071c5c7c8f3f5a790555b 100644 (file)
@@ -42,6 +42,7 @@ struct ID;
 struct Main;
 struct ListBase;
 struct ARegion;
+struct ARegionType;
 struct ScrArea;
 struct wmWindow;
 struct wmWindowManager;
@@ -660,6 +661,7 @@ void uiDrawPanels(const struct bContext *C, struct ARegion *ar);
 struct Panel *uiBeginPanel(struct ScrArea *sa, struct ARegion *ar, uiBlock *block, struct PanelType *pt, int *open);
 void uiEndPanel(uiBlock *block, int width, int height);
 void uiScalePanels(struct ARegion *ar, float new_width);
+void uiPanelClearType(struct wmWindowManager *wm, const struct ARegionType *art, const struct PanelType *type);
 
 /* Handlers
  *
index 9fbf2fe88982011ad29f9c5f4661b72d0c209be4..bcd495517844d2ea82c8cb1ec817f50f9a26a37c 100644 (file)
@@ -306,6 +306,31 @@ void uiEndPanel(uiBlock *block, int width, int height)
        }
 }
 
+void uiPanelClearType(wmWindowManager *wm, const ARegionType *art, const PanelType *type)
+{
+       wmWindow *win;
+       for (win = wm->windows.first; win; win = win->next) {
+               ScrArea *sa;
+               for (sa = win->screen->areabase.first; sa; sa = sa->next) {
+                       ARegion *ar;
+                       for (ar = sa->regionbase.first; ar; ar = ar->next) {
+                               if (ar->type == art) {
+                                       uiBlock *block, *nblock = ar->uiblocks.first;
+                                       while ((block = nblock)) {
+                                               nblock = block->next;
+                                               if (block->panel) {
+                                                       if (block->panel->type == type) {
+                                                               uiFreeBlock(block->evil_C, block);
+                                                               BLI_remlink(&ar->uiblocks, block);
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+}
+
 static void ui_offset_panel_block(uiBlock *block)
 {
        uiStyle *style = UI_GetStyleDraw();
index 137ffecac9a07de4790b35012b761296c39e0729..cae9673906e9b47ec5514ae1ee09a03bf694d76c 100644 (file)
@@ -165,8 +165,9 @@ static void panel_draw_header(const bContext *C, Panel *pnl)
        RNA_parameter_list_free(&list);
 }
 
-static void rna_Panel_unregister(Main *UNUSED(bmain), StructRNA *type)
+static void rna_Panel_unregister(Main *bmain, StructRNA *type)
 {
+       wmWindowManager *wm;
        ARegionType *art;
        PanelType *pt = RNA_struct_blender_type_get(type);
 
@@ -174,6 +175,10 @@ static void rna_Panel_unregister(Main *UNUSED(bmain), StructRNA *type)
                return;
        if (!(art = region_type_find(NULL, pt->space_type, pt->region_type)))
                return;
+
+       for (wm = bmain->wm.first; wm; wm = wm->id.next) {
+               uiPanelClearType(wm, art, pt);
+       }
        
        RNA_struct_free_extension(type, &pt->ext);