Revision: 48396
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48396
Author:   campbellbarton
Date:     2012-06-29 10:52:37 +0000 (Fri, 29 Jun 2012)
Log Message:
-----------
fix for crash scaling an image

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_image.h
    trunk/blender/source/blender/blenkernel/intern/image.c
    trunk/blender/source/blender/makesrna/intern/rna_image_api.c

Modified: trunk/blender/source/blender/blenkernel/BKE_image.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_image.h 2012-06-29 10:12:42 UTC 
(rev 48395)
+++ trunk/blender/source/blender/blenkernel/BKE_image.h 2012-06-29 10:52:37 UTC 
(rev 48396)
@@ -191,7 +191,7 @@
 void BKE_image_merge(struct Image *dest, struct Image *source);
 
 /* scale the image */
-void BKE_image_scale(struct Image *image, int width, int height);
+int BKE_image_scale(struct Image *image, int width, int height);
 
 /* check if texture has alpha (depth=32) */
 int BKE_image_has_alpha(struct Image *image);

Modified: trunk/blender/source/blender/blenkernel/intern/image.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/image.c      2012-06-29 
10:12:42 UTC (rev 48395)
+++ trunk/blender/source/blender/blenkernel/intern/image.c      2012-06-29 
10:52:37 UTC (rev 48396)
@@ -514,17 +514,21 @@
 }
 
 /* note, we could be clever and scale all imbuf's but since some are mipmaps 
its not so simple */
-void BKE_image_scale(Image *image, int width, int height)
+int BKE_image_scale(Image *image, int width, int height)
 {
        ImBuf *ibuf;
        void *lock;
 
        ibuf = BKE_image_acquire_ibuf(image, NULL, &lock);
 
-       IMB_scaleImBuf(ibuf, width, height);
-       ibuf->userflags |= IB_BITMAPDIRTY;
+       if (ibuf) {
+               IMB_scaleImBuf(ibuf, width, height);
+               ibuf->userflags |= IB_BITMAPDIRTY;
+       }
 
        BKE_image_release_ibuf(image, lock);
+
+       return (ibuf != NULL);
 }
 
 Image *BKE_image_load(const char *filepath)

Modified: trunk/blender/source/blender/makesrna/intern/rna_image_api.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_image_api.c        
2012-06-29 10:12:42 UTC (rev 48395)
+++ trunk/blender/source/blender/makesrna/intern/rna_image_api.c        
2012-06-29 10:52:37 UTC (rev 48396)
@@ -178,9 +178,11 @@
        IMB_rect_from_float(ibuf);
 }
 
-static void rna_Image_scale(Image *image, int width, int height)
+static void rna_Image_scale(Image *image, int width, int height, , ReportList 
*reports)
 {
-       BKE_image_scale(image, width, height);
+       if (!BKE_image_scale(image, width, height)) {
+               BKE_reportf(reports, RPT_ERROR, "Image \"%s\" does not have any 
image data", image->id.name + 2);
+       }
 }
 
 static int rna_Image_gl_load(Image *image, ReportList *reports, int filter, 
int mag)
@@ -285,6 +287,7 @@
 
        func = RNA_def_function(srna, "scale", "rna_Image_scale");
        RNA_def_function_ui_description(func, "Scale the image in pixels");
+       RNA_def_function_flag(func, FUNC_USE_REPORTS);
        parm = RNA_def_int(func, "width", 0, 1, 10000, "", "Width", 1, 10000);
        RNA_def_property_flag(parm, PROP_REQUIRED);
        parm = RNA_def_int(func, "height", 0, 1, 10000, "", "Height", 1, 10000);

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to