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

Fix crashes when saving layers to USD files in specific edge cases. #4018

Merged

Conversation

jufrantz
Copy link
Contributor

This addresses a crash encountered in production assets since maya-usd v0.30.0. The crash occurs during the save to USD operation, it is triggered by dereferencing a null SdfLayerHandle returned by UsdStage::GetUsedLayers(true) in LayerDatabase::saveUsdToMayaFile. Maya outputs this error:

maya.bin crashed. FATAL ERROR: attempted member lookup on NULL TfWeakPtr<SdfLayer>  

Upon investigation, the crash is linked to the presence of USD value clips using auto-generated manifest layers in the stage. The auto-generated manifest layer - returned by GetUsedLayers(true) - becomes null after a stage recomposition. This recomposition is triggered midway through the "save loop" within MayaUsd::utils::saveLayerWithFormat, as the stage cache is updated to reflect potential layer path changes.

Unfortunately, the issue occurs with very complex production scenes that I cannot share, and I have not been able to reproduce it with simpler scenes yet.

Included changes
  • Avoid unnecessary stage recomposition in saveLayerWithFormat when the root layer's path did not change. This reduces related instability.
  • Verify layers returned by UsdStage::GetUsedLayers(), even though null layers are not expected, to handle edge cases like this gracefully.

…ot layer to USD.

saveLayerWithFormat was unconditionally updating related stages, and
updateAllCachedStageWithLayer is calling UsdStage::SetLoadRules.
As of USD v24.11, this triggers a full recomposition unconditionally.
Verify layers to prevent potential dereferencing of null handle during
save operations. While UsdStage::GetUsedLayers() is not expected to
return null layers, an edge case was observed in production scenes using
valueClips with auto-generated manifest layers.
…le during save.

While UsdStage::GetUsedLayers() is not expected to return null layers,
an edge case was observed in production scenes using valueClips with
auto-generated manifest layers.
Copy link
Collaborator

@pierrebai-adsk pierrebai-adsk left a comment

Choose a reason for hiding this comment

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

Thank you for submitting these hard to find bug fixes!

@seando-adsk seando-adsk added the workflows Related to in-context workflows label Dec 3, 2024
@seando-adsk seando-adsk added the ready-for-merge Development process is finished, PR is ready for merge label Dec 3, 2024
@seando-adsk seando-adsk merged commit 652667a into Autodesk:dev Dec 3, 2024
11 checks passed
@seando-adsk
Copy link
Collaborator

@jufrantz Thanks for fixing this crash.

@jufrantz jufrantz deleted the fix_potential_crash_on_save_to_usd_files branch December 3, 2024 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-merge Development process is finished, PR is ready for merge workflows Related to in-context workflows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants