Fix 'usdcat --flattenLayerStack' output #2832
Merged
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.
Description of Change(s)
This PR addresses 2 issues:
usdcat --flattenLayerStack ...
outputting the wrong data, and a crash when calling the command on a non-existant file.The first issue was due to the logic guiding what to export. If the
stage
was initialized, it would export it. Otherwise, it would export thelayer
. This doesn't work because, in the presence of the--flattenLayerStack
flag, both thestage
and thelayer
are initialized, but thelayer
should be exported. Instead, it was outputting the flattened, unloaded stage. To fix this, I simply flipped the order of the conditional blocks so that thestage
is only exported in the absence of thelayer
. Since the only conditional branches that can result in both thestage
andlayer
being initialized are bound to the--flattenLayerStack
flag, we can verify that this change does not impact the behavior of any of the other cases.The second issue is the result of an unsafe assumption that the input file is valid. Since the
--flattenLayerStack
command generates the layer from the input stage, we need to be sure that the stage successfully opened before creating the layer.UsdUtilsFlattenLayerStack
expects a valid stage as input, so giving it aTfNullPtr
results in a crash. I addressed this by requiring that the stage exist before runningUsdUtilsFlattenLayerStack
.I also added a couple of new test cases that should help prevent similar issues from happening in the future.
Fixes Issue(s)
N/A
I have verified that all unit tests pass with the proposed changes
I have submitted a signed Contributor License Agreement