Skip to content

Commit 7e3c3ff

Browse files
santosg87samuelliu-adsk
authored andcommitted
Fix crash by adding nullptr check for camera parent and add unit tests
1 parent 1308a55 commit 7e3c3ff

File tree

6 files changed

+27
-2
lines changed

6 files changed

+27
-2
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ Installers for MayaUSD can be found [here](https://github.com/Autodesk/maya-usd/
3030
- 2023
3131
- 2024
3232
- 2025
33+
- 2026
3334

3435

3536
## Plugin Documentation
3637
+ [Getting Started with USD in Maya 2022](https://help.autodesk.com/view/MAYAUL/2022/ENU/?guid=GUID-36CFE2C3-766F-4B00-8464-E94F95E7AF4B)
3738
+ [Getting Started with USD in Maya 2023](https://help.autodesk.com/view/MAYAUL/2023/ENU/?guid=GUID-36CFE2C3-766F-4B00-8464-E94F95E7AF4B)
3839
+ [Getting Started with USD in Maya 2024](https://help.autodesk.com/view/MAYAUL/2024/ENU/?guid=GUID-36CFE2C3-766F-4B00-8464-E94F95E7AF4B)
3940
+ [Getting Started with USD in Maya 2025](https://help.autodesk.com/view/MAYAUL/2025/ENU/?guid=GUID-36CFE2C3-766F-4B00-8464-E94F95E7AF4B)
41+
+ [Getting Started with USD in Maya 2026](https://help.autodesk.com/view/MAYAUL/2026/ENU/?guid=GUID-36CFE2C3-766F-4B00-8464-E94F95E7AF4B)
4042

4143
## Building
4244
Everything needed to build maya-usd is provided in the form of source and a devkit that needs to be installed. Unit tests are provided for all projects and can be optionally built and executed using google tests. Full details on how to build and test maya-usd can be found in [BUILD.md](doc/build.md)

lib/mayaUsd/ufe/MayaUsdObject3d.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ bool MayaUsdObject3d::visibility() const
7373
// check if the parent is visible
7474
auto parentItem = Ufe::Hierarchy::createItem(parentPath);
7575
auto parentObject3d = Ufe::Object3d::object3d(parentItem);
76-
if (!parentObject3d->visibility()) {
76+
if (parentObject3d && !parentObject3d->visibility()) {
7777
return false;
7878
}
7979
parentPath = parentPath.pop();

lib/usdUfe/ufe/UsdCamera.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ bool UsdCamera::computedVisibility() const
497497
// check if the parent is visible
498498
auto parentItem = Ufe::Hierarchy::createItem(parentPath);
499499
auto parentObject3d = Ufe::Object3d::object3d(parentItem);
500-
if (!parentObject3d->visibility()) {
500+
if (parentObject3d && !parentObject3d->visibility()) {
501501
return false;
502502
}
503503
parentPath = parentPath.pop();

test/lib/mayaUsd/render/vp2RenderDelegate/testVP2RenderDelegateCameras.py

+23
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
from maya import cmds
2828

29+
from pxr import Usd
30+
2931
import unittest
3032
import ufe
3133
import os
@@ -117,12 +119,33 @@ def _RunTest(self):
117119
cmds.currentTime(4)
118120
self.assertSnapshotClose('%s_animation.png' % (self._testName))
119121

122+
# test camera creation and visibility
123+
self._TestUsdCameraCreationAndVisibility()
124+
120125
def _GetSceneItem(self, mayaPathString, usdPathString):
121126
mayaPathSegment = mayaUtils.createUfePathSegment(mayaPathString)
122127
usdPathSegment = usdUtils.createUfePathSegment(usdPathString)
123128
ufePath = ufe.Path([mayaPathSegment, usdPathSegment])
124129
ufeItem = ufe.Hierarchy.createItem(ufePath)
125130
return ufeItem
131+
132+
def _TestUsdCameraCreationAndVisibility(self):
133+
usdFilePath = cmds.internalVar(utd=1) + '/testCamera.usda'
134+
stage = Usd.Stage.CreateNew(usdFilePath)
135+
# Create camera under a def
136+
scope = stage.DefinePrim('/parent', 'Scope')
137+
defPrim = stage.DefinePrim('/cam', '')
138+
camera = stage.DefinePrim('/parent/cam/camera1', 'Camera')
139+
stage.GetRootLayer().Save()
140+
proxyShape = cmds.createNode('mayaUsdProxyShape')
141+
cmds.setAttr('mayaUsdProxyShape1.filePath', usdFilePath, type='string')
142+
ufeItem = ufeUtils.createItem('|mayaUsdProxy1|mayaUsdProxyShape1,/parent')
143+
object3d = ufe.Object3d.object3d(ufeItem)
144+
object3d.setVisibility(False)
145+
self.assertSnapshotClose('%s_invisibile.png' % (self._testName))
146+
object3d.setVisibility(True)
147+
self.assertSnapshotClose('%s_visibile.png' % (self._testName))
148+
126149

127150
@unittest.skipUnless(mayaUtils.mayaMajorVersion() > 2025, 'Requires Maya fixes only available after Maya 2025.')
128151
def testCameras(self):

0 commit comments

Comments
 (0)