Fix T47181: Blender OSL script node crash (OSL 1.6.9)

Compiling OSL scripts with errors in them would cause Blender to crash since the OSL version
bump to 1.6.9 instead of printing the error to the console as it did before.

With version 1.6.2, OSL added a pointer to an OpenImageIO ErrorHandler as an argument to the
OSLCompiler constructor. However, since it defaults to the NULL pointer, Blender still compiled
fine after the OSL version bump.
It turns out, though, that this pointer is used without further checks inside the OSL code, which
makes it crash when it tries to report an error unless a valid ErrorHandler pointer is specified.
Therefore, this commit simply passes a pointer to the static default handler that OIIO offers,
which prints the error to the console just like OSL did before.

Using this feature for a more advanced error handling and displaying from the Blender side would
be possible and seems reasonable, but for now it's not really relevant for fixing this bug.
This commit is contained in:
Lukas Stockner 2016-01-16 01:32:22 +01:00
parent 9a76354585
commit 70e16b3c99
Notes: blender-bot 2023-02-14 08:45:12 +01:00
Referenced by issue #47181, blender osl script node crash (osl 1.6.9)
1 changed files with 1 additions and 1 deletions

View File

@ -282,7 +282,7 @@ bool OSLShaderManager::osl_compile(const string& inputfile, const string& output
stdosl_path = path_get("shader/stdosl.h");
/* compile */
OSL::OSLCompiler *compiler = new OSL::OSLCompiler();
OSL::OSLCompiler *compiler = new OSL::OSLCompiler(&OSL::ErrorHandler::default_handler());
bool ok = compiler->compile(string_view(inputfile), options, string_view(stdosl_path));
delete compiler;