Fix (unreported) bad 'NULL freeing' with placeholder images.

Looks like code expects some initialized Image data after all, so do it
for placeholders as well (using default generated UV grid).
This commit is contained in:
Bastien Montagne 2016-04-29 18:05:49 +02:00
parent 57eb8539fc
commit 461604c0d5
3 changed files with 32 additions and 16 deletions

View File

@ -61,6 +61,8 @@ void BKE_image_free_buffers(struct Image *image);
/* call from library */
void BKE_image_free(struct Image *image);
void BKE_image_init(struct Image *image);
typedef void (StampCallback)(void *data, const char *propname, char *propvalue, int len);
void BKE_render_result_stamp_info(struct Scene *scene, struct Object *camera, struct RenderResult *rr, bool allocate_only);

View File

@ -350,27 +350,41 @@ void BKE_image_free(Image *ima)
}
/* only image block itself */
static void image_init(Image *ima, short source, short type)
{
BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(ima, id));
ima->ok = IMA_OK;
ima->xrep = ima->yrep = 1;
ima->aspx = ima->aspy = 1.0;
ima->gen_x = 1024; ima->gen_y = 1024;
ima->gen_type = IMA_GENTYPE_GRID;
ima->source = source;
ima->type = type;
if (source == IMA_SRC_VIEWER)
ima->flag |= IMA_VIEW_AS_RENDER;
BKE_color_managed_colorspace_settings_init(&ima->colorspace_settings);
ima->stereo3d_format = MEM_callocN(sizeof(Stereo3dFormat), "Image Stereo Format");
}
void BKE_image_init(struct Image *image)
{
if (image) {
image_init(image, IMA_SRC_GENERATED, IMA_TYPE_UV_TEST);
}
}
static Image *image_alloc(Main *bmain, const char *name, short source, short type)
{
Image *ima;
ima = BKE_libblock_alloc(bmain, ID_IM, name);
if (ima) {
ima->ok = IMA_OK;
ima->xrep = ima->yrep = 1;
ima->aspx = ima->aspy = 1.0;
ima->gen_x = 1024; ima->gen_y = 1024;
ima->gen_type = 1; /* no defines yet? */
ima->source = source;
ima->type = type;
if (source == IMA_SRC_VIEWER)
ima->flag |= IMA_VIEW_AS_RENDER;
BKE_color_managed_colorspace_settings_init(&ima->colorspace_settings);
ima->stereo3d_format = MEM_callocN(sizeof(Stereo3dFormat), "Image Stereo Format");
image_init(ima, source, type);
}
return ima;

View File

@ -931,7 +931,7 @@ void BKE_libblock_init_empty(ID *id)
BKE_texture_default((Tex *)id);
break;
case ID_IM:
/* Image is a bit complicated, for now assume NULLified im is OK. */
BKE_image_init((Image *)id);
break;
case ID_LT:
BKE_lattice_init((Lattice *)id);