Fix use-after-free of meshes shared across finalized models#3637
Open
caugonnet wants to merge 1 commit into
Open
Fix use-after-free of meshes shared across finalized models#3637caugonnet wants to merge 1 commit into
caugonnet wants to merge 1 commit into
Conversation
ModelBuilder.finalize() stores only the raw uint64 wp.Mesh id in model.shape_source_ptr, while Mesh.finalize() rebound self.mesh to a new wp.Mesh on every call. Since replicate() and add_builder() share geometry objects by reference, finalizing a second model built from the same source released the wp.Mesh referenced by the first model, leaving its shape_source_ptr dangling; mesh queries then walked freed BVH memory (CUDA illegal memory access). Fix it on two levels so neither path can dangle: - Mesh.finalize() now caches the finalized wp.Mesh per device (and requires_grad/bvh_constructor) instead of clobbering the previous one, so re-finalizing shared geometry returns the same mesh id. The cache is invalidated when vertices or indices are reassigned. - ModelBuilder.finalize() keeps model-owned strong references to every finalized wp.Mesh (Model._mesh_keep_alive), mirroring the existing heightfield_meshes keep-alive, so a model's meshes stay alive for the model's lifetime independent of the geometry objects. Signed-off-by: Cedric AUGONNET <caugonnet@nvidia.com>
|
caugonnet
requested a deployment
to
external-pr-approval
July 24, 2026 07:59 — with
GitHub Actions
Waiting
caugonnet
requested a deployment
to
external-pr-approval
July 24, 2026 07:59 — with
GitHub Actions
Waiting
Contributor
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughMesh finalization now caches device-specific Warp meshes and invalidates caches when geometry changes. Models retain finalized mesh references, and a replication regression test verifies shared meshes survive subsequent finalization and garbage collection. ChangesShared mesh lifetime protection
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ModelBuilder.finalize() stores only the raw uint64 wp.Mesh id in model.shape_source_ptr, while Mesh.finalize() rebound self.mesh to a new wp.Mesh on every call. Since replicate() and add_builder() share geometry objects by reference, finalizing a second model built from the same source released the wp.Mesh referenced by the first model, leaving its shape_source_ptr dangling; mesh queries then walked freed BVH memory (CUDA illegal memory access).
Fix it on two levels so neither path can dangle:
Description
Checklist
CHANGELOG.mdhas been updated (if user-facing change)Test plan
Bug fix
Steps to reproduce:
Minimal reproduction:
New feature / API change
Summary by CodeRabbit
Bug Fixes
Tests