MaterialX icon indicating copy to clipboard operation
MaterialX copied to clipboard

NodeDef Lookup Order is OS Dependent

Open feldstj opened this issue 2 years ago • 2 comments

When selecting a nodedef, the following cache is used: std::unordered_multimap<string, NodeDefPtr> nodeDefMap;

Looking up the first matching nodedef in this cache is unfortunately OS dependent. Why? The unordered_multimap has no strict rules associated with the order of identical keys and it looks like Linux adds keys to the front while Windows adds to the back when the keys are the same. As a result lookups are OS dependent.

Recommendation: Change to: unordered_map<std::string, std::vector<NodeDefPtr>> to maintain the declaration order found in the library.

feldstj avatar Dec 04 '23 18:12 feldstj

This is a great catch, @feldstj, and it sounds very worthwhile to fix this.

For developers who are less familiar with this area of the code, here's a link to the unordered multimap that you're referencing in this issue:

https://github.com/AcademySoftwareFoundation/MaterialX/blob/36be87205ee01e6f81dc26b8fe7c79ba5d6c840b/source/MaterialXCore/Document.cpp#L158

If you have the bandwidth, feel free to propose a pull request with the fix you describe above; otherwise, we'll plan to take a look at this on our side.

jstone-lucasfilm avatar Jan 26 '24 18:01 jstone-lucasfilm

Hey @jstone-lucasfilm, unfortunately I'm pretty swamped at the moment. If one of you guys could look into it, I'd really appreciate it. Thanks.

feldstj avatar Jan 29 '24 12:01 feldstj

Thanks for this recommendation, @feldstj, and this has now been addressed in #1753.

jstone-lucasfilm avatar Mar 26 '24 18:03 jstone-lucasfilm