Skip to content

Commit

Permalink
Fix inline variable parsing (#1191)
Browse files Browse the repository at this point in the history
This changelist fixes the parsing of inline source code variables, where a single bracket would incorrectly be interpreted as a prefix/suffix marker.
  • Loading branch information
jstone-lucasfilm authored Jan 7, 2023
1 parent c58bbfb commit faff163
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions source/MaterialXGenShader/Nodes/SourceCodeNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@

MATERIALX_NAMESPACE_BEGIN

namespace
{

const string INLINE_VARIABLE_PREFIX("{{");
const string INLINE_VARIABLE_SUFFIX("}}");

} // anonymous namespace

ShaderNodeImplPtr SourceCodeNode::create()
{
return std::make_shared<SourceCodeNode>();
Expand Down Expand Up @@ -97,17 +105,14 @@ void SourceCodeNode::emitFunctionCall(const ShaderNode& node, GenContext& contex
{
// An inline function call

static const string prefix("{{");
static const string postfix("}}");

size_t pos = 0;
size_t i = _functionSource.find_first_of(prefix);
size_t i = _functionSource.find(INLINE_VARIABLE_PREFIX);
StringSet variableNames;
StringVec code;
while (i != string::npos)
{
code.push_back(_functionSource.substr(pos, i - pos));
size_t j = _functionSource.find_first_of(postfix, i + 2);
size_t j = _functionSource.find(INLINE_VARIABLE_SUFFIX, i + 2);
if (j == string::npos)
{
throw ExceptionShaderGenError("Malformed inline expression in implementation for node " + node.getName());
Expand Down Expand Up @@ -146,7 +151,7 @@ void SourceCodeNode::emitFunctionCall(const ShaderNode& node, GenContext& contex
}

pos = j + 2;
i = _functionSource.find_first_of(prefix, pos);
i = _functionSource.find(INLINE_VARIABLE_PREFIX, pos);
}
code.push_back(_functionSource.substr(pos));

Expand Down

0 comments on commit faff163

Please sign in to comment.