openexr icon indicating copy to clipboard operation
openexr copied to clipboard

ImfErrorMessage C Api and multithreading

Open dlemstra opened this issue 2 years ago • 1 comments

The ImfErrorMessage method uses a shared buffer errorMessage and this could result in an incorrect error messages when multiple images copy an exception message into that same errorbuffer. Would it be possible to make some changes to make the error message file specific?

An option would be to "attach" the error message to the ImfInputFile struct but that will not work for the ImfOpenInputFile method. Maybe a new method could be used to store "something" on the ImfInputFile that would store an error message. Maybe something like this:

ImfContext *context;
ImfInputFile *file;
const char *error_message;

context=ImfContextOpenInputFile(filename);
file=ImfContextGetInputFile(context);
error_message=ImfContextErrorMessage(context);
ImfContextClose(context);

This approach would prevent breaking changes to the C API but would allow having an error message per image.

dlemstra avatar Dec 02 '21 21:12 dlemstra

Thanks for pointing this out.

Just fyi, this will all get revamped slightly when we switch the C++ api to use the new C core library, and then the "friendly" C api will get similar updates. In the core library, each file is a "context" where you can set error handlers, memory allocators, the like, and so the only stateful things are the global defaults for things which are used to initialize a context if you don't set the values.

kdt3rd avatar Feb 12 '22 20:02 kdt3rd

Closing this now because it seems that this has been addressed in the new C api.

dlemstra avatar May 11 '24 11:05 dlemstra