Fix abort when rendering with OSL and OptiX in Cycles

LLVM could kill the process during OSL PTX code generation, due
to generated symbols contained invalid characters in their name.
Those names are generated by Cycles and were not properly filtered:

- If the locale was set to something other than the minimal locale
  (when Blender was built with WITH_INTERNATIONAL), pointers
  may be printed with grouping characters, like commas or dots,
  added to them.
- Material names from Blender may contain the full range of UTF8
  characters.

This fixes those cases by forcing the locale used in the symbol name
generation to the minimal locale and using the material name hash
instead of the actual material name string.
This commit is contained in:
Patrick Mours 2022-11-10 19:27:07 +01:00
parent 2688d7200a
commit 6a8ce5ec1c
1 changed files with 7 additions and 5 deletions

View File

@ -641,6 +641,8 @@ string OSLCompiler::id(ShaderNode *node)
{
/* assign layer unique name based on pointer address + bump mode */
stringstream stream;
stream.imbue(std::locale("C")); /* Ensure that no grouping characters (e.g. commas with en_US
locale) are added to the pointer string */
stream << "node_" << node->type->name << "_" << node;
return stream.str();
@ -1132,12 +1134,12 @@ OSL::ShaderGroupRef OSLCompiler::compile_type(Shader *shader, ShaderGraph *graph
{
current_type = type;
string name = shader->name.string();
/* Replace invalid characters. */
for (size_t i; (i = name.find_first_of(" .,:;+-*/#")) != string::npos;)
name.replace(i, 1, "_");
/* Use name hash to identify shader group to avoid issues with non-alphanumeric characters */
stringstream name;
name.imbue(std::locale("C"));
name << "shader_" << shader->name.hash();
OSL::ShaderGroupRef group = ss->ShaderGroupBegin(name);
OSL::ShaderGroupRef group = ss->ShaderGroupBegin(name.str());
ShaderNode *output = graph->output();
ShaderNodeSet dependencies;