avoid having dangling panel pointers in the interface, unregistering addons could leave the interface pointing to freed memory.

This commit is contained in:
Campbell Barton
2013-01-09 06:00:33 +00:00
parent cecbb3498b
commit 9b5a2084bc
3 changed files with 33 additions and 1 deletions

View File

@@ -42,6 +42,7 @@ struct ID;
struct Main; struct Main;
struct ListBase; struct ListBase;
struct ARegion; struct ARegion;
struct ARegionType;
struct ScrArea; struct ScrArea;
struct wmWindow; struct wmWindow;
struct wmWindowManager; 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); 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 uiEndPanel(uiBlock *block, int width, int height);
void uiScalePanels(struct ARegion *ar, float new_width); void uiScalePanels(struct ARegion *ar, float new_width);
void uiPanelClearType(struct wmWindowManager *wm, const struct ARegionType *art, const struct PanelType *type);
/* Handlers /* Handlers
* *

View 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) static void ui_offset_panel_block(uiBlock *block)
{ {
uiStyle *style = UI_GetStyleDraw(); uiStyle *style = UI_GetStyleDraw();

View File

@@ -165,8 +165,9 @@ static void panel_draw_header(const bContext *C, Panel *pnl)
RNA_parameter_list_free(&list); 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; ARegionType *art;
PanelType *pt = RNA_struct_blender_type_get(type); PanelType *pt = RNA_struct_blender_type_get(type);
@@ -175,6 +176,10 @@ static void rna_Panel_unregister(Main *UNUSED(bmain), StructRNA *type)
if (!(art = region_type_find(NULL, pt->space_type, pt->region_type))) if (!(art = region_type_find(NULL, pt->space_type, pt->region_type)))
return; return;
for (wm = bmain->wm.first; wm; wm = wm->id.next) {
uiPanelClearType(wm, art, pt);
}
RNA_struct_free_extension(type, &pt->ext); RNA_struct_free_extension(type, &pt->ext);
BLI_freelinkN(&art->paneltypes, pt); BLI_freelinkN(&art->paneltypes, pt);