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

Improperly created scene item must not crash move tool. #1636

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/mayaUsd/ufe/UsdTransform3dCommonAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,10 @@ Ufe::Transform3d::Ptr
UsdTransform3dCommonAPIHandler::transform3d(const Ufe::SceneItem::Ptr& item) const
{
UsdSceneItem::Ptr usdItem = std::dynamic_pointer_cast<UsdSceneItem>(item);
#if !defined(NDEBUG)
assert(usdItem);
#endif

if (!usdItem) {
return nullptr;
}

// If the prim supports the common transform API, create a common API
// interface for it, otherwise delegate to the next handler in the chain of
Expand All @@ -294,11 +295,10 @@ Ufe::Transform3d::Ptr UsdTransform3dCommonAPIHandler::editTransform3d(
const Ufe::SceneItem::Ptr& item UFE_V2(, const Ufe::EditTransform3dHint& hint)) const
{
UsdSceneItem::Ptr usdItem = std::dynamic_pointer_cast<UsdSceneItem>(item);
#if !defined(NDEBUG)

if (!usdItem) {
TF_FATAL_ERROR("Could not create common API Transform3d interface for null item.");
return nullptr;
}
#endif

// If the prim supports the common transform API, create a common API
// interface for it, otherwise delegate to the next handler in the chain of
Expand Down
6 changes: 2 additions & 4 deletions lib/mayaUsd/ufe/UsdTransform3dFallbackMayaXformStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,10 @@ Ufe::Transform3d::Ptr createEditTransform3dImp(
std::vector<UsdGeomXformOp>::const_iterator& firstFallbackOp)
{
UsdSceneItem::Ptr usdItem = std::dynamic_pointer_cast<UsdSceneItem>(item);
#if !defined(NDEBUG)

if (!usdItem) {
TF_FATAL_ERROR(
"Could not create fallback Maya transform stack Transform3d interface for null item.");
return nullptr;
}
#endif

// If the prim isn't transformable, can't create a Transform3d interface
// for it.
Expand Down
10 changes: 8 additions & 2 deletions lib/mayaUsd/ufe/UsdTransform3dMatrixOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,10 @@ UsdTransform3dMatrixOpHandler::transform3d(const Ufe::SceneItem::Ptr& item) cons
// We must create a Transform3d interface to edit the whole object,
// e.g. setting the local transformation matrix for the complete object.
UsdSceneItem::Ptr usdItem = std::dynamic_pointer_cast<UsdSceneItem>(item);
TF_AXIOM(usdItem);

if (!usdItem) {
return nullptr;
}

UsdGeomXformable xformable(usdItem->prim());
bool unused;
Expand Down Expand Up @@ -405,7 +408,10 @@ Ufe::Transform3d::Ptr UsdTransform3dMatrixOpHandler::editTransform3d(
const Ufe::SceneItem::Ptr& item UFE_V2(, const Ufe::EditTransform3dHint& hint)) const
{
UsdSceneItem::Ptr usdItem = std::dynamic_pointer_cast<UsdSceneItem>(item);
TF_AXIOM(usdItem);

if (!usdItem) {
return nullptr;
}

// Beware: the default UsdGeomXformOp constructor
// https://github.com/PixarAnimationStudios/USD/blob/71b4baace2044ea4400ba802e91667f9ebe342f0/pxr/usd/usdGeom/xformOp.h#L148
Expand Down
6 changes: 2 additions & 4 deletions lib/mayaUsd/ufe/UsdTransform3dMayaXformStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,10 @@ Ufe::Transform3d::Ptr
createTransform3d(const Ufe::SceneItem::Ptr& item, NextTransform3dFn nextTransform3dFn)
{
UsdSceneItem::Ptr usdItem = std::dynamic_pointer_cast<UsdSceneItem>(item);
#if !defined(NDEBUG)

if (!usdItem) {
TF_FATAL_ERROR(
"Could not create Maya transform stack Transform3d interface for null item.");
return nullptr;
}
#endif

// If the prim isn't transformable, can't create a Transform3d interface
// for it.
Expand Down
13 changes: 9 additions & 4 deletions lib/mayaUsd/ufe/UsdTransform3dPointInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,11 @@ UsdTransform3dPointInstanceHandler::transform3d(const Ufe::SceneItem::Ptr& item)
{
UsdSceneItem::Ptr usdItem = downcast(item);

if (!usdItem || !usdItem->isPointInstance()) {
if (!usdItem) {
return nullptr;
}

if (!usdItem->isPointInstance()) {
return _nextHandler->transform3d(item);
}

Expand All @@ -171,9 +175,10 @@ Ufe::Transform3d::Ptr UsdTransform3dPointInstanceHandler::editTransform3d(
const Ufe::EditTransform3dHint& hint) const
{
UsdSceneItem::Ptr usdItem = downcast(item);
#if !defined(NDEBUG)
assert(usdItem);
#endif

if (!usdItem) {
return nullptr;
}

if (!usdItem->isPointInstance()) {
return _nextHandler->editTransform3d(item, hint);
Expand Down
32 changes: 32 additions & 0 deletions test/lib/ufe/testMoveCmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,5 +394,37 @@ def createCommonAPI(testCase, sphereXformable):

self.runTestOpUndo(createCommonAPI, 'xformOp:translate')

def testBadSceneItem(self):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Test Driven Development: wrote the test first, it crashed and failed, wrote the fix, test passes.

'''Improperly constructed scene item should not crash Maya.'''

# MAYA-112601 / GitHub #1169: improperly constructed Python scene item
# should not cause a crash.
cmds.file(new=True, force=True)

import mayaUsd_createStageWithNewLayer
proxyShape = mayaUsd_createStageWithNewLayer.createStageWithNewLayer()

proxyShapePath = ufe.PathString.path(proxyShape)
proxyShapeItem = ufe.Hierarchy.createItem(proxyShapePath)
proxyShapeContextOps = ufe.ContextOps.contextOps(proxyShapeItem)
proxyShapeContextOps.doOp(['Add New Prim', 'Sphere'])

spherePath = ufe.PathString.path('%s,/Sphere1' % proxyShape)
# The proper way to create a scene item is the following:
#
# sphereItem = ufe.Hierarchy.createItem(spherePath)
#
# A naive user can create a scene item as the following. The resulting
# scene item is not a USD scene item: it is a Python base class scene
# item, which has a path but nothing else. This should not a crash
# when using the move command.
sphereItem = ufe.SceneItem(spherePath)

sn = ufe.GlobalSelection.get()
sn.clear()
sn.append(sphereItem)

cmds.move(0, 10, 0, relative=True, os=True, wd=True)

if __name__ == '__main__':
unittest.main(verbosity=2)