Skip to content

Commit

Permalink
When dealing with an explicit target on definition search. First test…
Browse files Browse the repository at this point in the history
… for implemtnations which have a non-empty target string.

If not found then fallback to non-target implementations.
This should fix returning non-target implementations before trying to find implementations with targets.
  • Loading branch information
kwokcb committed Jul 26, 2023
1 parent fa5b093 commit b8cdceb
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions source/MaterialXCore/Definition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,28 @@ InterfaceElementPtr NodeDef::getImplementation(const string& target) const
const TargetDefPtr targetDef = getDocument()->getTargetDef(target);
const StringVec candidateTargets = targetDef ? targetDef->getMatchingTargets() : StringVec();

// Search the candidate targets in order
// Search the candidate targets in inheritance order
for (const string& candidateTarget : candidateTargets)
{
for (InterfaceElementPtr interface : interfaces)
{
if (targetStringsMatch(interface->getTarget(), candidateTarget))
const std::string& interfaceTarget = interface->getTarget();
if (!interfaceTarget.empty() && targetStringsMatch(interfaceTarget, candidateTarget))
{
return interface;
}
}
}
// If no exact target match is found then return the first interface without a target
for (InterfaceElementPtr interface : interfaces)
{
// Look for interfaces without targets
const std::string& interfaceTarget = interface->getTarget();
if (interfaceTarget.empty())
{
return interface;
}
}

return InterfaceElementPtr();
}
Expand Down

0 comments on commit b8cdceb

Please sign in to comment.