[Bf-blender-cvs] [3620ce7f678] blender-v3.0-release: Fix T92503: Cycles OSL crash with material previews

Brecht Van Lommel noreply at git.blender.org
Thu Oct 28 16:01:58 CEST 2021


Commit: 3620ce7f67874b8d891a41b66714112bed7a23a2
Author: Brecht Van Lommel
Date:   Thu Oct 28 15:46:20 2021 +0200
Branches: blender-v3.0-release
https://developer.blender.org/rB3620ce7f67874b8d891a41b66714112bed7a23a2

Fix T92503: Cycles OSL crash with material previews

===================================================================

M	intern/cycles/scene/osl.cpp

===================================================================

diff --git a/intern/cycles/scene/osl.cpp b/intern/cycles/scene/osl.cpp
index 09626cb48bb..c5f38d4f270 100644
--- a/intern/cycles/scene/osl.cpp
+++ b/intern/cycles/scene/osl.cpp
@@ -326,17 +326,22 @@ bool OSLShaderManager::osl_compile(const string &inputfile, const string &output
   string stdosl_path;
   string shader_path = path_get("shader");
 
-  /* specify output file name */
+  /* Specify output file name. */
   options.push_back("-o");
   options.push_back(outputfile);
 
-  /* specify standard include path */
+  /* Specify standard include path. */
   string include_path_arg = string("-I") + shader_path;
   options.push_back(include_path_arg);
 
   stdosl_path = path_join(shader_path, "stdcycles.h");
 
-  /* compile */
+  /* Compile.
+   *
+   * Mutex protected because the OSL compiler does not appear to be thread safe, see T92503. */
+  static thread_mutex osl_compiler_mutex;
+  thread_scoped_lock lock(osl_compiler_mutex);
+
   OSL::OSLCompiler *compiler = new OSL::OSLCompiler(&OSL::ErrorHandler::default_handler());
   bool ok = compiler->compile(string_view(inputfile), options, string_view(stdosl_path));
   delete compiler;



More information about the Bf-blender-cvs mailing list