Page MenuHome

osl compile fails to find headers includ'ed
Closed, ResolvedPublic

Description

System Information
FreeBSD 10.1 amd64 GTX520

Blender Version
Broken: 2.72+
Worked: 2.71

Short description of error
An osl script that uses #include "xxx.h" to make use of osl header files that ship with blender (inside addons/cycles/shader) fails to compile.

There are 5 files included that an osl script should be able to utilise - node_color.h node_fresnel.h node_texture.h oslutil.h stdosl.h

While stdosl.h is always included, adding it as an include to a script shouldn't break compiling the script.

Exact steps for others to reproduce the error
Compile an osl script within blender that has an #include line.

Fix
Within OSLShaderManager::osl_compile located in intern/cycles/render/osl.cpp the -I option flag and the path it specifies are being added to options as separate items, they need to be added as one string. options is a vector<string_view> so options.push_back() adds a new item to the list, unlike adding characters to the end of a string.

Just due to proximity - the #if test for the use of string and string_view is wrong. vector<string> is used in osl 1.4.x and vector<string_view> is used in osl 1.5.x and higher - included in this patch.

This patch fixes this issue for me.

diff --git a/intern/cycles/render/osl.cpp b/intern/cycles/render/osl.cpp
index 45b4d28..2200eb4 100644
--- a/intern/cycles/render/osl.cpp
+++ b/intern/cycles/render/osl.cpp
@@ -251,20 +251,19 @@ void OSLShaderManager::shading_system_free()
 
 bool OSLShaderManager::osl_compile(const string& inputfile, const string& outputfile)
 {
-#if OSL_LIBRARY_VERSION_CODE < 10602
-	vector<string_view> options;
-#else
+#if OSL_LIBRARY_VERSION_CODE < 10500
 	vector<string> options;
+#else
+	vector<string_view> options;
 #endif
 	string stdosl_path;
-	string shader_path = path_get("shader");
+	string shader_path = path_get("shader").insert(0,"-I");
 
 	/* specify output file name */
 	options.push_back("-o");
 	options.push_back(outputfile);
 
 	/* specify standard include path */
-	options.push_back("-I");
 	options.push_back(shader_path);
 
 	stdosl_path = path_get("shader/stdosl.h");

Event Timeline

Shane Ambler (sambler) set Type to Bug.
Shane Ambler (sambler) created this task.
Shane Ambler (sambler) raised the priority of this task from to Needs Triage by Developer.

My mistake, osl 1.6 has changed back to vector<string> so the osl test is correct based on the fact that we don't want to support osl < 1.5.12 based on response from @Sergey Sharybin (sergey) to D1062

Patch should be -

diff --git a/intern/cycles/render/osl.cpp b/intern/cycles/render/osl.cpp
index 45b4d28..69fb63d 100644
--- a/intern/cycles/render/osl.cpp
+++ b/intern/cycles/render/osl.cpp
@@ -257,14 +257,13 @@ bool OSLShaderManager::osl_compile(const string& inputfile, const string& output
 	vector<string> options;
 #endif
 	string stdosl_path;
-	string shader_path = path_get("shader");
+	string shader_path = path_get("shader").insert(0,"-I");
 
 	/* specify output file name */
 	options.push_back("-o");
 	options.push_back(outputfile);
 
 	/* specify standard include path */
-	options.push_back("-I");
 	options.push_back(shader_path);
 
 	stdosl_path = path_get("shader/stdosl.h");