MaterialX icon indicating copy to clipboard operation
MaterialX copied to clipboard

Incorrect usage of find_first_of in replacing {{in}} pattern

Open tomas-davidovic opened this issue 3 years ago • 2 comments

I am writing a very hacked together ShaderGen and found when I have sourcecode="{0}" where in the output I want to see literally {0}, MaterialX fails.

The problem is in the SourceCodeNode::emitFunctionCall method, which uses _functionSource.find_first_of("{{") to find the first occurrence of the {{. But that's not what find_first_of actually does. It finds the first occurrence of any of the characters in the provided string, so it finds even single {. The code should be using find instead, which finds the exact match. Same goes for the postfix search a bit later.

tomas-davidovic avatar Aug 24 '22 13:08 tomas-davidovic

This is a great catch, @tomas-davidovic, and I believe this issue goes back to our very first implementation of SourceCodeNode::emitFunctionCall. Would you have the bandwidth to put together a pull request addressing this, where you can validate the results with your local ShaderGen implementation?

jstone-lucasfilm avatar Aug 24 '22 14:08 jstone-lucasfilm

I can try (my very first PR on github ever).

tomas-davidovic avatar Aug 24 '22 15:08 tomas-davidovic

Thanks for this report, @tomas-davidovic, and this has been addressed in #1191.

jstone-lucasfilm avatar Jan 07 '23 22:01 jstone-lucasfilm