[Bf-blender-cvs] [961ac8e] master: Report errno string when writing files fails

Campbell Barton noreply at git.blender.org
Mon Jan 11 02:41:01 CET 2016


Commit: 961ac8eb85a6ede92c0d1bd062d2bdf264bbaef5
Author: Campbell Barton
Date:   Mon Jan 11 12:32:29 2016 +1100
Branches: master
https://developer.blender.org/rB961ac8eb85a6ede92c0d1bd062d2bdf264bbaef5

Report errno string when writing files fails

Screenshot ignored errors, some render code printed 'Saved' without checking for failure.

note: errno is now cleared from IMB_saveiff so all callers don't need to.

===================================================================

M	source/blender/blenkernel/intern/image.c
M	source/blender/editors/screen/screendump.c
M	source/blender/editors/space_image/image_ops.c
M	source/blender/imbuf/intern/writeimage.c
M	source/blender/makesrna/intern/rna_image_api.c
M	source/blender/render/intern/source/pipeline.c
M	source/blender/render/intern/source/render_result.c

===================================================================

diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index f640f11..7eea534 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -827,7 +827,9 @@ static ImBuf *add_ibuf_size(unsigned int width, unsigned int height, const char
 }
 
 /* adds new image block, creates ImBuf and initializes color */
-Image *BKE_image_add_generated(Main *bmain, unsigned int width, unsigned int height, const char *name, int depth, int floatbuf, short gen_type, const float color[4], const bool stereo3d)
+Image *BKE_image_add_generated(
+        Main *bmain, unsigned int width, unsigned int height, const char *name,
+        int depth, int floatbuf, short gen_type, const float color[4], const bool stereo3d)
 {
 	/* on save, type is changed to FILE in editsima.c */
 	Image *ima = image_alloc(bmain, name, IMA_SRC_GENERATED, IMA_TYPE_UV_TEST);
diff --git a/source/blender/editors/screen/screendump.c b/source/blender/editors/screen/screendump.c
index a701fc9..a354d11 100644
--- a/source/blender/editors/screen/screendump.c
+++ b/source/blender/editors/screen/screendump.c
@@ -30,6 +30,7 @@
 
 
 #include <string.h>
+#include <errno.h>
 
 #include "MEM_guardedalloc.h"
 
@@ -177,6 +178,7 @@ static void screenshot_crop(ImBuf *ibuf, rcti crop)
 static int screenshot_exec(bContext *C, wmOperator *op)
 {
 	ScreenshotData *scd = op->customdata;
+	bool ok = false;
 
 	if (scd == NULL) {
 		/* when running exec directly */
@@ -204,14 +206,20 @@ static int screenshot_exec(bContext *C, wmOperator *op)
 				/* bw screenshot? - users will notice if it fails! */
 				IMB_color_to_bw(ibuf);
 			}
-			BKE_imbuf_write(ibuf, path, &scd->im_format);
+			if (BKE_imbuf_write(ibuf, path, &scd->im_format)) {
+				ok = true;
+			}
+			else {
+				BKE_reportf(op->reports, RPT_ERROR, "Could not write image: %s", strerror(errno));
+			}
 
 			IMB_freeImBuf(ibuf);
 		}
 	}
 
 	screenshot_data_free(op);
-	return OPERATOR_FINISHED;
+
+	return ok ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
 }
 
 static int screenshot_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c
index 1d11e7c..c35f5ae 100644
--- a/source/blender/editors/space_image/image_ops.c
+++ b/source/blender/editors/space_image/image_ops.c
@@ -1580,7 +1580,9 @@ static void save_image_options_to_op(SaveImageOptions *simopts, wmOperator *op)
 	RNA_string_set(op->ptr, "filepath", simopts->filepath);
 }
 
-static void save_image_post(wmOperator *op, ImBuf *ibuf, Image *ima, int ok, int save_copy, const char *relbase, int relative, int do_newpath, const char *filepath)
+static void save_image_post(
+        wmOperator *op, ImBuf *ibuf, Image *ima, int ok, int save_copy,
+        const char *relbase, int relative, int do_newpath, const char *filepath)
 {
 	if (ok) {
 		if (!save_copy) {
@@ -1630,7 +1632,7 @@ static void save_image_post(wmOperator *op, ImBuf *ibuf, Image *ima, int ok, int
 		}
 	}
 	else {
-		BKE_reportf(op->reports, RPT_ERROR, "Could not write image %s", filepath);
+		BKE_reportf(op->reports, RPT_ERROR, "Could not write image: %s", strerror(errno));
 	}
 }
 
@@ -2151,7 +2153,7 @@ static int image_save_sequence_exec(bContext *C, wmOperator *op)
 			BLI_path_abs(name, bmain->name);
 
 			if (0 == IMB_saveiff(ibuf, name, IB_rect | IB_zbuf | IB_zbuffloat)) {
-				BKE_reportf(op->reports, RPT_ERROR, "Could not write image %s", name);
+				BKE_reportf(op->reports, RPT_ERROR, "Could not write image: %s", strerror(errno));
 				break;
 			}
 
diff --git a/source/blender/imbuf/intern/writeimage.c b/source/blender/imbuf/intern/writeimage.c
index 28710fb..84ec253 100644
--- a/source/blender/imbuf/intern/writeimage.c
+++ b/source/blender/imbuf/intern/writeimage.c
@@ -34,6 +34,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <errno.h>
 
 #include "BLI_utildefines.h"
 #include "BLI_path_util.h"
@@ -54,6 +55,8 @@ short IMB_saveiff(struct ImBuf *ibuf, const char *name, int flags)
 {
 	const ImFileType *type;
 
+	errno = 0;
+
 	BLI_assert(!BLI_path_is_rel(name));
 
 	if (ibuf == NULL) return (false);
diff --git a/source/blender/makesrna/intern/rna_image_api.c b/source/blender/makesrna/intern/rna_image_api.c
index 7280cc6..23643f7 100644
--- a/source/blender/makesrna/intern/rna_image_api.c
+++ b/source/blender/makesrna/intern/rna_image_api.c
@@ -48,6 +48,7 @@
 
 #ifdef RNA_RUNTIME
 
+#include <errno.h>
 #include "BKE_image.h"
 #include "BKE_packedFile.h"
 #include "BKE_main.h"
@@ -101,7 +102,7 @@ static void rna_Image_save_render(Image *image, bContext *C, ReportList *reports
 			write_ibuf->dither = scene->r.dither_intensity;
 
 			if (!BKE_imbuf_write(write_ibuf, path, &scene->r.im_format)) {
-				BKE_reportf(reports, RPT_ERROR, "Could not write image '%s'", path);
+				BKE_reportf(reports, RPT_ERROR, "Could not write image: %s, '%s'", strerror(errno), path);
 			}
 
 			if (write_ibuf != ibuf)
diff --git a/source/blender/render/intern/source/pipeline.c b/source/blender/render/intern/source/pipeline.c
index 1ac9dd8..75ef2fb 100644
--- a/source/blender/render/intern/source/pipeline.c
+++ b/source/blender/render/intern/source/pipeline.c
@@ -34,6 +34,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <stddef.h>
+#include <errno.h>
 
 #include "DNA_anim_types.h"
 #include "DNA_image_types.h"
@@ -198,6 +199,35 @@ static void stats_background(void *UNUSED(arg), RenderStats *rs)
 	fflush(stdout);
 }
 
+static void render_print_save_message(const char *name, int ok, int err)
+{
+	if (ok) {
+		printf("Saved: '%s'\n", name);
+	}
+	else {
+		printf("Render error (%s) cannot save: '%s'\n", strerror(err), name);
+	}
+}
+
+static int render_imbuf_write_stamp_test(
+        Scene *scene, struct RenderResult *rr, ImBuf *ibuf, const char *name,
+        const ImageFormatData *imf, bool stamp)
+{
+	int ok;
+
+	if (stamp) {
+		/* writes the name of the individual cameras */
+		ok = BKE_imbuf_write_stamp(scene, rr, ibuf, name, imf);
+	}
+	else {
+		ok = BKE_imbuf_write(ibuf, name, imf);
+	}
+
+	render_print_save_message(name, ok, errno);
+
+	return ok;
+}
+
 void RE_FreeRenderResult(RenderResult *res)
 {
 	render_result_free(res);
@@ -3209,8 +3239,8 @@ bool RE_WriteRenderViewsImage(ReportList *reports, RenderResult *rr, Scene *scen
 	if (ELEM(rd->im_format.imtype, R_IMF_IMTYPE_OPENEXR, R_IMF_IMTYPE_MULTILAYER) &&
 	    rd->im_format.views_format == R_IMF_VIEWS_MULTIVIEW)
 	{
-		RE_WriteRenderResult(reports, rr, name, &rd->im_format, true, NULL);
-		printf("Saved: %s\n", name);
+		ok = RE_WriteRenderResult(reports, rr, name, &rd->im_format, true, NULL);
+		render_print_save_message(name, ok, errno);
 	}
 
 	/* mono, legacy code */
@@ -3228,8 +3258,8 @@ bool RE_WriteRenderViewsImage(ReportList *reports, RenderResult *rr, Scene *scen
 			}
 
 			if (rd->im_format.imtype == R_IMF_IMTYPE_MULTILAYER) {
-				RE_WriteRenderResult(reports, rr, name, &rd->im_format, false, rv->name);
-				printf("Saved: %s\n", name);
+				ok = RE_WriteRenderResult(reports, rr, name, &rd->im_format, false, rv->name);
+				render_print_save_message(name, ok, errno);
 			}
 			else {
 				ImBuf *ibuf = render_result_rect_to_ibuf(rr, rd, view_id);
@@ -3237,18 +3267,7 @@ bool RE_WriteRenderViewsImage(ReportList *reports, RenderResult *rr, Scene *scen
 				IMB_colormanagement_imbuf_for_write(ibuf, true, false, &scene->view_settings,
 				                                    &scene->display_settings, &rd->im_format);
 
-				if (stamp) {
-					/* writes the name of the individual cameras */
-					ok = BKE_imbuf_write_stamp(scene, rr, ibuf, name, &rd->im_format);
-				}
-				else {
-					ok = BKE_imbuf_write(ibuf, name, &rd->im_format);
-				}
-
-				if (ok == false) {
-					printf("Render error: cannot save %s\n", name);
-				}
-				else printf("Saved: %s\n", name);
+				ok = render_imbuf_write_stamp_test(scene, rr, ibuf, name, &rd->im_format, stamp);
 
 				/* optional preview images for exr */
 				if (ok && rd->im_format.imtype == R_IMF_IMTYPE_OPENEXR && (rd->im_format.flag & R_IMF_FLAG_PREVIEW_JPG)) {
@@ -3263,14 +3282,7 @@ bool RE_WriteRenderViewsImage(ReportList *reports, RenderResult *rr, Scene *scen
 					IMB_colormanagement_imbuf_for_write(ibuf, true, false, &scene->view_settings,
 					                                    &scene->display_settings, &imf);
 
-					if (stamp) {
-						/* writes the name of the individual cameras */
-						ok = BKE_imbuf_write_stamp(scene, rr, ibuf, name, &imf);
-					}
-					else {
-						ok = BKE_imbuf_write(ibuf, name, &imf);
-					}
-					printf("Saved: %s\n", name);
+					ok = render_imbuf_write_stamp_test(scene, rr, ibuf, name, &imf, stamp);
 				}
 
 				/* imbuf knows which rects are not part of ibuf */
@@ -3299,15 +3311,7 @@ bool RE_WriteRenderViewsImage(ReportList *reports, RenderResult *rr, Scene *scen
 
 			ibuf_arr[2] = IMB_stereo3d_ImBuf(&scene->r.im_format, ibuf_arr[0], ibuf_arr[1]);
 
-			if (stamp)
-				ok = BKE_imbuf_write_stamp(scene, rr, ibuf_arr[2], name, &rd->im_format);
-			else
-				ok = BKE_imbuf_write(ibuf_arr[2], name, &rd->im_format);
-
-			if (ok == false)
-				printf("Render error: cannot save %s\n", name);
-			else
-				printf("Saved: %s\n", name);
+			ok = render_imbuf_write_stamp_test(scene, rr, ibuf_arr[2], name, &rd->im_format, stamp);
 
 			/* optional preview images for exr */
 			if (ok && rd->im_format.imtype == R_IMF_IMTYPE_OPENEXR &&
@@ -3325,12 +3329,7 @@ bool RE_WriteRenderViewsImage(ReportList *reports, RenderResult *rr, Scene *scen
 				IMB_colormanagement_imbuf_for_write(ibuf_arr[2], true, false, &scene->view_settings,
 				                                    &scene->display_settings, &imf);
 
-				if (stamp)
-					ok = BKE_imbuf_write_stamp(scene, rr, ibuf_arr[2], name, &rd->im_format);
-				else
-					ok = BKE_imbuf_write(ibuf_arr[2], name, &imf);
-
-				printf("Saved: %s\n", name);
+				ok = render_imbuf_write_stamp_test(scene, rr, ibuf_arr[2], name, &rd->im_format, stamp);
 			}
 
 			/* imbuf knows which rects are not part of ibuf */
diff --git a/source/blender/render/intern/source/render_result.c b/source/blender/render/intern/source/render_result.c
index 19b049e..c89adc4 100644
--- a/sourc

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list