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.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user