Skip to content

Commit

Permalink
Merge pull request #2219 from AnimalLogic/csyshing/fix_transform_chai…
Browse files Browse the repository at this point in the history
…n_dead_loop_issue

[al] Fixed dead loop issue when deleting node
  • Loading branch information
seando-adsk authored Apr 6, 2022
2 parents 4423533 + 2732123 commit e18929a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
19 changes: 14 additions & 5 deletions plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyShapeSelection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,6 @@ void ProxyShape::makeUsdTransformsInternal(
/// must always exist, and never get deleted.
auto check = m_requiredPaths.find(prim.GetPath());
if (check == m_requiredPaths.end()) {
UsdPrim prim = *it;

MObject node;
createMayaNode(
prim,
Expand All @@ -611,7 +609,7 @@ void ProxyShape::makeUsdTransformsInternal(

TransformReference transformRef(node, reason);
transformRef.checkIncRef(reason);
const SdfPath path { usdPrim.GetPath() };
const SdfPath path { prim.GetPath() };
m_requiredPaths.emplace(path, transformRef);

TF_DEBUG(ALUSDMAYA_SELECTION)
Expand Down Expand Up @@ -698,8 +696,19 @@ void ProxyShape::removeUsdTransformChain(

// The Xform of the shape may have already been deleted when the shape was deleted
if (h.isAlive() && h.isValid()) {
modifier.reparentNode(object);
modifier.deleteNode(object);
// Note: For some reason if deleting Maya object with MDagModifier,
// the parents of the node will also be deleted.
// The usual trick:
// modifier.reparentNode(object);
// modifier.deleteNode(object);
// that re-parent the object before deleting does not work here,
// the workaround here is to delete the node with MGlobal instead.
if (MGlobal::deleteNode(object) != MStatus::kSuccess) {
MString err;
err.format(
"Failed to delete Maya node for prim path ^1s.", parentPrim.GetText());
MGlobal::displayError(err);
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/Scope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ MBoundingBox Scope::boundingBox() const
MBoundingBox bbox = MPxTransform::boundingBox();

UsdPrim prim = transform()->prim();
if (prim) {
// Calculate bbox only if there is a proxy shape connected
if (foundShape && prim) {
// Get purpose draw states
bool drawRenderPurpose = false;
bool drawProxyPurpose = false;
Expand Down

0 comments on commit e18929a

Please sign in to comment.