Image: Log errors during image write when using OpenImageIO

Before this change, any accumulated errors from OpenImageIO would be
lost and a nonsensical use of `errno` would be used instead.

An example of the new error log:
```
00:23.188  image.write      | ERROR OpenImageIO write failed: sgi image resolution may not exceed 65535x65535, you asked for 65536x1
```

Pull Request: https://projects.blender.org/blender/blender/pulls/146554
This commit is contained in:
Jesse Yurkovich
2025-09-22 20:26:55 +02:00
committed by Jesse Yurkovich
parent 0c3f633024
commit 12cdfb5856
2 changed files with 10 additions and 3 deletions

View File

@@ -2569,7 +2569,7 @@ bool BKE_imbuf_write(ImBuf *ibuf, const char *filepath, const ImageFormatData *i
BKE_image_format_to_imbuf(ibuf, imf);
const bool ok = IMB_save_image(ibuf, filepath, IB_byte_data);
if (ok == 0) {
if (!ok && errno != 0) {
perror(filepath);
}

View File

@@ -23,6 +23,7 @@
#include "CLG_log.h"
static CLG_LogRef LOG_READ = {"image.read"};
static CLG_LogRef LOG_WRITE = {"image.write"};
OIIO_NAMESPACE_USING
@@ -132,7 +133,7 @@ static ImBuf *load_pixels(
bool ok = in->read_image(
0, 0, 0, channels, format, ibuf_data, ibuf_xstride, -ibuf_ystride, AutoStride);
if (!ok) {
CLOG_ERROR(&LOG_READ, "OpenImageIO read failed: failed: %s", in->geterror().c_str());
CLOG_ERROR(&LOG_READ, "OpenImageIO read failed: %s", in->geterror().c_str());
IMB_freeImBuf(ibuf);
return nullptr;
@@ -364,7 +365,13 @@ bool imb_oiio_write(const WriteContext &ctx, const char *filepath, const ImageSp
}
}
return write_ok && close_ok;
const bool all_ok = write_ok && close_ok;
if (!all_ok) {
CLOG_ERROR(&LOG_WRITE, "OpenImageIO write failed: %s", out->geterror().c_str());
errno = 0; /* Prevent higher level layers from calling `perror` unnecessarily. */
}
return all_ok;
}
WriteContext imb_create_write_context(const char *file_format,