Fix memory leak from loading files with legacy grease pencil palettes
This commit is contained in:
parent
b4d3bd134b
commit
cdac2642ea
|
@ -84,6 +84,8 @@ bool BKE_gpencil_free_strokes(struct bGPDframe *gpf);
|
|||
void BKE_gpencil_free_frames(struct bGPDlayer *gpl);
|
||||
/** Free all of the gp-layers for a viewport (list should be `&gpd->layers` or so). */
|
||||
void BKE_gpencil_free_layers(struct ListBase *list);
|
||||
/** Free all of the palettes (list should be `&gpd->palettes` or so). */
|
||||
void BKE_gpencil_free_legacy_palette_data(struct ListBase *list);
|
||||
/** Free (or release) any data used by this grease pencil (does not free the gpencil itself). */
|
||||
void BKE_gpencil_free_data(struct bGPdata *gpd, bool free_all);
|
||||
/**
|
||||
|
|
|
@ -443,10 +443,21 @@ void BKE_gpencil_free_layers(ListBase *list)
|
|||
}
|
||||
}
|
||||
|
||||
/* Free all of the gp-palettes and colors. */
|
||||
void BKE_gpencil_free_legacy_palette_data(ListBase *list)
|
||||
{
|
||||
LISTBASE_FOREACH_MUTABLE (bGPDpalette *, palette, list) {
|
||||
BLI_freelistN(&palette->colors);
|
||||
MEM_freeN(palette);
|
||||
}
|
||||
BLI_listbase_clear(list);
|
||||
}
|
||||
|
||||
void BKE_gpencil_free_data(bGPdata *gpd, bool free_all)
|
||||
{
|
||||
/* free layers */
|
||||
BKE_gpencil_free_layers(&gpd->layers);
|
||||
BKE_gpencil_free_legacy_palette_data(&gpd->palettes);
|
||||
|
||||
/* materials */
|
||||
MEM_SAFE_FREE(gpd->mat);
|
||||
|
|
|
@ -40,41 +40,6 @@
|
|||
|
||||
#include "gpencil_intern.h"
|
||||
|
||||
/* Free all of a gp-colors */
|
||||
static void free_gpencil_colors(bGPDpalette *palette)
|
||||
{
|
||||
/* error checking */
|
||||
if (palette == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* free colors */
|
||||
BLI_freelistN(&palette->colors);
|
||||
}
|
||||
|
||||
/* Free all of the gp-palettes and colors */
|
||||
static void free_palettes(ListBase *list)
|
||||
{
|
||||
bGPDpalette *palette_next;
|
||||
|
||||
/* error checking */
|
||||
if (list == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* delete palettes */
|
||||
for (bGPDpalette *palette = static_cast<bGPDpalette *>(list->first); palette;
|
||||
palette = palette_next)
|
||||
{
|
||||
palette_next = palette->next;
|
||||
/* free palette colors */
|
||||
free_gpencil_colors(palette);
|
||||
|
||||
MEM_freeN(palette);
|
||||
}
|
||||
BLI_listbase_clear(list);
|
||||
}
|
||||
|
||||
/* ***************** Convert old 2.7 files to 2.8 ************************ */
|
||||
static bool gpencil_convert_old_files_poll(bContext *C)
|
||||
{
|
||||
|
@ -138,7 +103,7 @@ static int gpencil_convert_old_files_exec(bContext *C, wmOperator *op)
|
|||
}
|
||||
|
||||
/* free palettes */
|
||||
free_palettes(&gpd->palettes);
|
||||
BKE_gpencil_free_legacy_palette_data(&gpd->palettes);
|
||||
|
||||
/* disable all GP modes */
|
||||
ED_gpencil_setup_modes(C, gpd, 0);
|
||||
|
|
Loading…
Reference in New Issue