osl compile fails to find headers includ'ed #43561

Closed
opened 2015-02-04 14:46:58 +01:00 by Shane Ambler · 8 comments

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");

**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"); ```
Author

Changed status to: 'Open'

Changed status to: 'Open'
Author

Added subscriber: @sambler

Added subscriber: @sambler
Author

Added subscriber: @Sergey

Added subscriber: @Sergey
Author

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 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");
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 to [D1062](https://archive.blender.org/developer/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"); ```

This issue was referenced by f8c650aa7a

This issue was referenced by f8c650aa7a8fd72a85f9bb1297b02510b089702a

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'

Closed by commit f8c650aa7a.

Closed by commit f8c650aa7a.

This issue was referenced by blender/cycles@512374d580

This issue was referenced by blender/cycles@512374d5805dbd27e482f144ad0c0bc9e3a7c81b
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#43561
No description provided.