Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2016-01-11 04:32:29 +0300
committerCampbell Barton <ideasman42@gmail.com>2016-01-11 04:32:29 +0300
commit961ac8eb85a6ede92c0d1bd062d2bdf264bbaef5 (patch)
treea7c28997d99792827db4004058ee6c5608a1b265 /source
parentf28d3955e9c848c32e340ec6696142ef124562d5 (diff)
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.
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/intern/image.c4
-rw-r--r--source/blender/editors/screen/screendump.c12
-rw-r--r--source/blender/editors/space_image/image_ops.c8
-rw-r--r--source/blender/imbuf/intern/writeimage.c3
-rw-r--r--source/blender/makesrna/intern/rna_image_api.c3
-rw-r--r--source/blender/render/intern/source/pipeline.c77
-rw-r--r--source/blender/render/intern/source/render_result.c5
7 files changed, 65 insertions, 47 deletions
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index f640f113c04..7eea53497b2 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 a701fc9ccb7..a354d1145fe 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 1d11e7c6287..c35f5ae14c5 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 28710fba823..84ec2534e7f 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 7280cc622dc..23643f722d6 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 1ac9dd8e716..75ef2fbb048 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 19b049ee1da..c89adc4a814 100644
--- a/source/blender/render/intern/source/render_result.c
+++ b/source/blender/render/intern/source/render_result.c
@@ -32,6 +32,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <errno.h>
#include "MEM_guardedalloc.h"
@@ -1134,6 +1135,8 @@ bool RE_WriteRenderResult(ReportList *reports, RenderResult *rr, const char *fil
}
}
+ errno = 0;
+
BLI_make_existing_file(filename);
if (IMB_exr_begin_write(exrhandle, filename, width, height, compress, rr->stamp_data)) {
@@ -1142,7 +1145,7 @@ bool RE_WriteRenderResult(ReportList *reports, RenderResult *rr, const char *fil
}
else {
/* TODO, get the error from openexr's exception */
- BKE_report(reports, RPT_ERROR, "Error writing render result (see console)");
+ BKE_reportf(reports, RPT_ERROR, "Error writing render result, %s (see console)", strerror(errno));
success = false;
}