Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HYDRA-1457 : Fix UsdStageMap::allStages to not rely on the internal cache when it can be outdated #4128

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions lib/mayaUsd/ufe/UsdStageMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,21 +257,21 @@ UsdStageMap::StageSet UsdStageMap::allStages()
{
rebuildIfDirty();

// We can't rely on using the cached paths to find all the stages.
// There might have been changes made to the stages, but we might not
// yet have received the notification(s) required to update the cache,
// and so the cache might not have been dirtied just yet.
// Therefore, directly query the Maya data model to get the most up-to-date
// info. This will add any missing stages in the cache. If there are outdated
// stages in the cache, they will be cleared on the next cache rebuild, or
// the next time anyone queries such an outdated stage.
StageSet stages;
for (auto it = _pathToObject.begin(); it != _pathToObject.end();
/* no ++it here, we manually move it in the loop */) {
const auto& pair = *it;
const Ufe::Path& path = pair.first;
// Calling UsdStageMap::stage may erase the entry in fPathToObject at path.
// Advance the iterator so that the iterator stays valid if erasure occurs.
it++;
// Now handle path.
PXR_NS::UsdStageWeakPtr matchingStage = stage(path);
// After this point pair and path cannot be safely used, they may have been erased.
// If the object cached in fPathToObject was invalid we'll get back a nullptr.
// Don't add nullptr to the returned StageSet.
if (matchingStage)
stages.insert(matchingStage);
for (const auto& proxyShapeName : ProxyShapeHandler::getAllNames()) {
auto proxyShapePath = toPath(proxyShapeName);
auto foundStage = stage(proxyShapePath);
if (foundStage) {
stages.insert(foundStage);
}
}
return stages;
}
Expand Down