From 0c036ad9e8252e7c8684250ef0ffca6e7c7074d2 Mon Sep 17 00:00:00 2001 From: dendenxu Date: Tue, 14 Oct 2025 16:49:37 +0800 Subject: [PATCH] Fix unfinished multi-part file loading in the py This commit fixes the issue where an unfinished multi-part file could not be loaded properly in the python warpper for OpenEXR. This happens when headers for the multi-part file are written to disk but the actual pixels never finish being written. The current fix skips the corrupted or empty parts with no pixel data while retaining the ability for loading the correct ones. Signed-off-by: dendenxu --- src/wrappers/python/PyOpenEXR.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/wrappers/python/PyOpenEXR.cpp b/src/wrappers/python/PyOpenEXR.cpp index 2063c3ce73..09c1043467 100644 --- a/src/wrappers/python/PyOpenEXR.cpp +++ b/src/wrappers/python/PyOpenEXR.cpp @@ -209,17 +209,29 @@ PyFile::PyFile(const std::string& filename, bool separate_channels, bool header_ // auto type = header.type(); - if (type == SCANLINEIMAGE || type == TILEDIMAGE) + try { - P.readPixels(*_inputFile, header.channels(), shape, rgbaChannels, dw, separate_channels); + if (type == SCANLINEIMAGE || type == TILEDIMAGE) + { + P.readPixels(*_inputFile, header.channels(), shape, rgbaChannels, dw, separate_channels); + } + else if (type == DEEPSCANLINE || type == DEEPTILE) + { + P.readDeepPixels(*_inputFile, type, header.channels(), shape, rgbaChannels, dw, separate_channels); + } + parts.append(py::cast(PyPart(P))); } - else if (type == DEEPSCANLINE || type == DEEPTILE) + catch (const std::exception& e) { - P.readDeepPixels(*_inputFile, type, header.channels(), shape, rgbaChannels, dw, separate_channels); + // Log the error and skip appending this part + py::print("Warning: Exception raised reading pixel data for part", part_index, "-", e.what()); } } - - parts.append(py::cast(PyPart(P))); + else + { + // If only reading the header, always append this part + parts.append(py::cast(PyPart(P))); + } } // for parts }