Skip to content

Commit a6fb5c6

Browse files
nvidia-jomillermeshula
authored andcommitted
[usdUtils] Prevent ComputeAllDependenciesClient from adding invalid layers
`UsdUtils_ComputeAllDependenciesClient` would output invalid layers if a layer fails to open. A check is added to make sure the layer opens correctly. If the layer does not open correctly, a warning will be issued Closes PixarAnimationStudios#3647 (Internal change: 2370359)
1 parent c0716b1 commit a6fb5c6

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

pxr/usd/usdUtils/dependencies.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "pxr/usd/sdf/fileFormat.h"
1818
#include "pxr/usd/sdf/layerUtils.h"
1919

20+
#include "pxr/base/tf/diagnostic.h"
2021
#include "pxr/base/trace/trace.h"
2122

2223
#include <functional>
@@ -126,7 +127,12 @@ struct UsdUtils_ComputeAllDependenciesClient
126127
}
127128
}
128129
else if (UsdStage::IsSupportedFile(anchoredPath)) {
129-
layers.insert(SdfLayer::FindOrOpen(anchoredPath));
130+
SdfLayerRefPtr dependencyLayer = SdfLayer::FindOrOpen(anchoredPath);
131+
if (dependencyLayer) {
132+
layers.insert(dependencyLayer);
133+
} else {
134+
TF_WARN("Failed to open dependency layer: %s (%s)", dependency.c_str(), anchoredPath.c_str());
135+
}
130136
}
131137
else {
132138
assets.insert(resolvedPath);

pxr/usd/usdUtils/testenv/testUsdUtilsDependencies.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Licensed under the terms set forth in the LICENSE.txt file available at
66
# https://openusd.org/license.
77

8-
from pxr import Ar, UsdUtils, Sdf, Usd
8+
from pxr import Ar, Tf, UsdUtils, Sdf, Usd
99
from pathlib import Path
1010
import os
1111
import unittest
@@ -294,6 +294,28 @@ def test_ComputeAllDependenciesMissingExternalDep(self):
294294
self.assertEqual(unresolved, ["missing.png",
295295
"missing_in_package.png",
296296
"missing_in_reference.png"])
297+
298+
def test_ComputeAllDependenciesInvalidPayload(self):
299+
"""Tests that invalid payloads are detected and reported"""
300+
301+
def TestDirPath(path):
302+
return os.path.normcase(
303+
os.path.abspath(os.path.join(testDir, path)))
304+
305+
testDir = "computeAllDependenciesInvalidPayload"
306+
stagePath = "root.usda"
307+
308+
delegate = UsdUtils.CoalescingDiagnosticDelegate()
309+
310+
layers, references, unresolved = UsdUtils.ComputeAllDependencies(TestDirPath(stagePath))
311+
self.assertEqual(len(layers), 1)
312+
self.assertEqual(os.path.normcase(layers[0].identifier), TestDirPath(stagePath))
313+
self.assertEqual(len(references), 0)
314+
self.assertEqual(len(unresolved), 0)
315+
316+
unfiltered = delegate.TakeUncoalescedDiagnostics()
317+
self.assertEqual(len(unfiltered), 1)
318+
self.assertTrue(unfiltered[0].commentary.startswith("Failed to open dependency layer: ./invalid.usd "))
297319

298320
if __name__=="__main__":
299321
unittest.main()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#usda 1.0
2+
3+
def "foo"
4+
{
5+
def "invalid" (
6+
prepend payload = @./invalid.usd@
7+
)
8+
{
9+
10+
}
11+
}

0 commit comments

Comments
 (0)