Skip to content

Commit 7ee5a8f

Browse files
[usdUtils] Prevent ComputeAllDependenciesClient from adding invalid layers
UsdUtils_ComputeAllDependenciesClient would output invalid layers if a layer fails to open. If the layer does not open correctly, an error will be posted
1 parent 53d7d64 commit 7ee5a8f

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-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_RUNTIME_ERROR("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: 15 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,20 @@ 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+
with self.assertRaises(Tf.ErrorException):
309+
layers, assets, unresolved = \
310+
UsdUtils.ComputeAllDependencies(TestDirPath(stagePath))
297311

298312
if __name__=="__main__":
299313
unittest.main()

pxr/usd/usdUtils/testenv/testUsdUtilsDependencies/computeAllDependenciesInvalidPayload/invalid.usd

Whitespace-only changes.
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)