Fix (unreported) bad 'NULL freeing' with placeholder images.
authorBastien Montagne <montagne29@wanadoo.fr>
Fri, 29 Apr 2016 16:05:49 +0000 (18:05 +0200)
committerBastien Montagne <montagne29@wanadoo.fr>
Fri, 29 Apr 2016 16:05:49 +0000 (18:05 +0200)
Looks like code expects some initialized Image data after all, so do it
for placeholders as well (using default generated UV grid).

source/blender/blenkernel/BKE_image.h
source/blender/blenkernel/intern/image.c
source/blender/blenkernel/intern/library.c

index 894ccae0dc8c4c4290c28116954e992907bb536d..eb98268c9f00ae6e2a88457587747ede29e55a4b 100644 (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);
index 340b406722fd8223d87e785a6e04122c06085407..d5f9a2dac3e5b9430bdc14a5731d217b0fc4ad2b 100644 (file)
@@ -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;
index 895d215ca91fcb93248e1b3b793f30199e753845..9e81cded9f5e261d04f45f5adea7e7c72d2c9d9e 100644 (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);