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

MAYA-126881 fix crash when editing two prims #2806

Merged
merged 1 commit into from
Jan 10, 2023
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
16 changes: 16 additions & 0 deletions lib/mayaUsd/fileio/primUpdaterManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1308,6 +1308,14 @@ bool PrimUpdaterManager::discardPrimEdits(const Ufe::Path& pulledPath)
toApplyOnLoop.loopAdvance();
}

#ifdef HAS_ORPHANED_NODES_MANAGER
if (_orphanedNodesManager) {
if (!TF_VERIFY(RemovePullVariantInfoUndoItem::execute(_orphanedNodesManager, pulledPath))) {
return false;
}
}
#endif

if (!FunctionUndoItem::execute(
"Discard edits pull info removal",
[pulledPath]() {
Expand Down Expand Up @@ -1391,6 +1399,14 @@ bool PrimUpdaterManager::discardOrphanedEdits(const MDagPath& dagPath, const Ufe
toApplyOnLoop.loopAdvance();
}

#ifdef HAS_ORPHANED_NODES_MANAGER
if (_orphanedNodesManager) {
if (!TF_VERIFY(RemovePullVariantInfoUndoItem::execute(_orphanedNodesManager, pulledPath))) {
return false;
}
}
#endif

if (!TF_VERIFY(removePullParent(pullParent, pulledPath))) {
return false;
}
Expand Down
33 changes: 32 additions & 1 deletion test/lib/mayaUsd/fileio/testDiscardEdits.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import fixturesUtils

from mayaUtils import setMayaTranslation
from usdUtils import createSimpleXformScene
from usdUtils import createSimpleXformScene, createDuoXformScene
from ufeUtils import ufeFeatureSetVersion

import mayaUsd.lib
Expand Down Expand Up @@ -119,6 +119,37 @@ def testDiscardEdits(self):
with self.assertRaises(RuntimeError):
om.MSelectionList().add(aMayaPathStr)

@unittest.skipUnless(ufeFeatureSetVersion() >= 3, 'Test only available in UFE v3 or greater.')
def testDiscardEditsDuo(self):
'''
Discard edits and re-edit on a USD transform when multiple separate edits are active.
It should not crash.
'''

# Edit as Maya first.
(ps,
aXlateOp, aUsdXlation, aUsdUfePathStr, aUsdUfePath, aUsdItem,
bXlateOp, bUsdXlation, bUsdUfePathStr, bUsdUfePath, bUsdItem) = createDuoXformScene()

with mayaUsd.lib.OpUndoItemList():
self.assertTrue(mayaUsd.lib.PrimUpdaterManager.editAsMaya(aUsdUfePathStr))

with mayaUsd.lib.OpUndoItemList():
self.assertTrue(mayaUsd.lib.PrimUpdaterManager.editAsMaya(bUsdUfePathStr))

bMayaItem = ufe.GlobalSelection.get().front()
bMayaXlation = om.MVector(4, 5, 6)
(bMayaPath, bMayaPathStr, bFn, mayaMatrix) = \
setMayaTranslation(bMayaItem, bMayaXlation)

# Discard Maya edits of B.
with mayaUsd.lib.OpUndoItemList():
self.assertTrue(mayaUsd.lib.PrimUpdaterManager.discardEdits(bMayaPathStr))

with mayaUsd.lib.OpUndoItemList():
self.assertTrue(mayaUsd.lib.PrimUpdaterManager.editAsMaya(bUsdUfePathStr))


@unittest.skipUnless(ufeFeatureSetVersion() >= 3, 'Test only available in UFE v3 or greater.')
def testDiscardEditsWhenParentIsDeactivated(self):
'''Discard edits on a USD transform when its parent is deactivated shoudl fail but not crash.'''
Expand Down
57 changes: 57 additions & 0 deletions test/testUtils/usdUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,63 @@ def createSimpleXformScene():
aXlateOp, aXlation, aUsdUfePathStr, aUsdUfePath, aUsdItem,
bXlateOp, bXlation, bUsdUfePathStr, bUsdUfePath, bUsdItem)

def createDuoXformSceneInCurrentLayer(psPathStr, ps):
'''Create a simple scene in the current stage and layer with a trivial hierarchy:

A translation (1, 2, 3)
B translation (7, 8, 9)

Returns a tuple of:
- A translation op, A translation vector
- A UFE path string, A UFE path, A UFE item
- B translation op, B translation vector
- B UFE path string, B UFE path, B UFE item
'''

stage = mayaUsd.lib.GetPrim(psPathStr).GetStage()
aPrim = stage.DefinePrim('/A', 'Xform')
aXformable = UsdGeom.Xformable(aPrim)
aXlateOp = aXformable.AddTranslateOp()
aXlation = Gf.Vec3d(1, 2, 3)
aXlateOp.Set(aXlation)
aUsdUfePathStr = psPathStr + ',/A'
aUsdUfePath = ufe.PathString.path(aUsdUfePathStr)
aUsdItem = ufe.Hierarchy.createItem(aUsdUfePath)

bPrim = stage.DefinePrim('/B', 'Xform')
bXformable = UsdGeom.Xformable(bPrim)
bXlateOp = bXformable.AddTranslateOp()
bXlation = Gf.Vec3d(7, 8, 9)
bXlateOp.Set(bXlation)
bUsdUfePathStr = psPathStr + ',/B'
bUsdUfePath = ufe.PathString.path(bUsdUfePathStr)
bUsdItem = ufe.Hierarchy.createItem(bUsdUfePath)

return (aXlateOp, aXlation, aUsdUfePathStr, aUsdUfePath, aUsdItem,
bXlateOp, bXlation, bUsdUfePathStr, bUsdUfePath, bUsdItem)

def createDuoXformScene():
'''Create a simple scene with a trivial hierarchy:

A translation (1, 2, 3)
B translation (7, 8, 9)

Returns a tuple of:
- proxy shape UFE item
- A translation op, A translation vector
- A UFE path string, A UFE path, A UFE item
- B translation op, B translation vector
- B UFE path string, B UFE path, B UFE item

Note: the proxy shape path and path string are not returned for compatibility with existing tests.
'''
(psPathStr, psPath, ps) = createSimpleStage()
(aXlateOp, aXlation, aUsdUfePathStr, aUsdUfePath, aUsdItem,
bXlateOp, bXlation, bUsdUfePathStr, bUsdUfePath, bUsdItem) = createDuoXformSceneInCurrentLayer(psPathStr, ps)
return (ps,
aXlateOp, aXlation, aUsdUfePathStr, aUsdUfePath, aUsdItem,
bXlateOp, bXlation, bUsdUfePathStr, bUsdUfePath, bUsdItem)

def createLayeredStage(layersCount = 3):
'''Create a stage with multiple layers, by default 3 extra layers:

Expand Down