Merge branch 'master' into free-refcount-ids
[blender.git] / source / blender / blenkernel / intern / image.c
index c421c67d9e58f21c3994e8f83ba83f8f29a2c855..d3ab1e4f3eb4002e06122b822ed78aeab81d4105 100644 (file)
@@ -329,20 +329,22 @@ void BKE_image_free_buffers(Image *ima)
        ima->ok = IMA_OK;
 }
 
-/* called by library too, do not free ima itself */
-void BKE_image_free(Image *ima)
+/**
+ * Free (or release) any data used by this image (does not free the image itself).
+ *
+ * \param ima The image to free.
+ * \param do_id_user When \a true, ID datablocks used (referenced) by this image are 'released'
+ *                   (their user count is decreased).
+ */
+void BKE_image_free(Image *ima, const bool UNUSED(do_id_user))
 {
        int a;
 
+       /* Also frees animdata. */
        BKE_image_free_buffers(ima);
 
        image_free_packedfiles(ima);
 
-       BKE_icon_id_delete(&ima->id);
-       ima->id.icon_id = 0;
-
-       BKE_previewimg_free(&ima->preview);
-
        for (a = 0; a < IMA_MAX_RENDER_SLOT; a++) {
                if (ima->renders[a]) {
                        RE_FreeRenderResult(ima->renders[a]);
@@ -351,7 +353,10 @@ void BKE_image_free(Image *ima)
        }
 
        image_free_views(ima);
-       MEM_freeN(ima->stereo3d_format);
+       MEM_SAFE_FREE(ima->stereo3d_format);
+
+       BKE_icon_id_delete(&ima->id);
+       BKE_previewimg_free(&ima->preview);
 }
 
 /* only image block itself */