diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2016-04-29 19:05:49 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2016-04-29 19:05:49 +0300 |
commit | 461604c0d5ea58bb44a2fac0a3637f5b959aac26 (patch) | |
tree | 1a3417aac5d1ee176d52084714c489b47122628a /source/blender | |
parent | 57eb8539fc5cab771828143dbfd100013b18db6e (diff) |
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).
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/BKE_image.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/image.c | 44 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/library.c | 2 |
3 files changed, 32 insertions, 16 deletions
diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h index 894ccae0dc8..eb98268c9f0 100644 --- a/source/blender/blenkernel/BKE_image.h +++ b/source/blender/blenkernel/BKE_image.h @@ -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); diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index 340b406722f..d5f9a2dac3e 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -350,27 +350,41 @@ void BKE_image_free(Image *ima) } /* only image block itself */ -static Image *image_alloc(Main *bmain, const char *name, short source, short type) +static void image_init(Image *ima, short source, short type) { - Image *ima; + BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(ima, id)); - ima = BKE_libblock_alloc(bmain, ID_IM, name); - if (ima) { - ima->ok = IMA_OK; + 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->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; + ima->source = source; + ima->type = type; - if (source == IMA_SRC_VIEWER) - ima->flag |= IMA_VIEW_AS_RENDER; + 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"); + 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) { + image_init(ima, source, type); } return ima; diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index 895d215ca91..9e81cded9f5 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -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); |