Skip to content

Fix end-iterator dereference when pruning source-to-targets map#2656

Open
kikou wants to merge 1 commit into
masterfrom
kikou/fix-source-targets-end-iter-deref
Open

Fix end-iterator dereference when pruning source-to-targets map#2656
kikou wants to merge 1 commit into
masterfrom
kikou/fix-source-targets-end-iter-deref

Conversation

@kikou
Copy link
Copy Markdown
Collaborator

@kikou kikou commented May 22, 2026

Summary

  • In HdArnoldRenderDelegate::HasPendingChanges, when handling the _dependencyRemovalQueue, the empty() check and the subsequent _sourceToTargetsMap.erase(sourceIt) ran outside the sourceIt != _sourceToTargetsMap.end() guard.
  • If the dependency was already absent from the map, find returned end() and we then dereferenced/erased that end iterator — undefined behavior.
  • Moved both calls inside the existing validity check so the prune only happens when the lookup actually found an entry.

Test plan

  • Render a scene that triggers dependency changes (e.g., reassign a material/light link), confirm no crash and dirty propagation still works.
  • Existing render_delegate testsuite passes.

The empty() check and subsequent erase ran outside the find()
validity guard, dereferencing end() whenever the source was not
present in _sourceToTargetsMap.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes undefined behavior in HdArnoldRenderDelegate::HasPendingChanges by ensuring _sourceToTargetsMap is only accessed/erased when the find() call actually returns a valid iterator, preventing an end() iterator dereference during dependency-pruning.

Changes:

  • Move sourceIt->second.empty() and _sourceToTargetsMap.erase(sourceIt) inside the sourceIt != _sourceToTargetsMap.end() guard.
  • Prevent potential crashes/UB when a dependency removal event references a source that is no longer present in _sourceToTargetsMap.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants