I don't think it's a bug. I originally deleted the modifier because it
would otherwise maintain reference to the mobject, presumably for undo.
Normally the modifier is created and destroyed in the same scope, which
implicitly deletes it once exiting that scope.

On 4 Jan 2018 18:33, <[email protected]> wrote:

Not sure about what maya does internally, but as a workaround (and maybe as
the only solution), you can make sure to delete all the children before
deleting the parent ?

from maya.api import OpenMaya as om
# create
fn = om.MFnDagNode()
hroots = []
for i in xrange(2):
    oroot = fn.create("transform")
    hroot = om.MObjectHandle(oroot)
    hroots.append(hroot)
    fnChild = om.MFnDagNode()
    for j in xrange(2):
        ochild = fnChild.create("transform")
        fn.addChild(ochild)

# delete
mdg_mod = om.MDGModifier()
for moh_node in hroots:
    if not moh_node.isValid():
        continue
    fnRoot = om.MFnDagNode(moh_node.object())
    # make sure the children are removed prior to deletion
    for j in xrange(fnRoot.childCount()):
        fnRoot.removeChildAt(0)
    mdg_mod.deleteNode(moh_node.object())
mdg_mod.doIt()
del mdg_mod


It looks like as soon as maya looses the target of a pointer, it crashes,
like to avoid the memory leak (yay ^^) ? But by deleting the children
first, you make sure nothing is left behind \o/



On Thursday, January 4, 2018 at 1:51:49 AM UTC-8, Rémi Deletrain wrote:
> Hi all,
>
>
> I trying too to delete a node. But I have a crash on doIt of MDGModifier
> From what I read here, the reason would come from the management of
pointers...
>
>
>
> But I don't know how to fix that or convert to exception.
> My process create many nodes. When I want to delete root of one of them
maya have brutal crash
>
>
> Here is my code:
>
>
>
> #   Delete node
> mdg_mod = OpenMaya.MDGModifier()
> for moh_node in self.a_roots:
>     if moh_node.isValid() is False:
>         continue
>     mdg_mod.deleteNode(moh_node.object())
> mdg_mod.doIt()
> del mdg_mod
>
> I Use MObjectHandle and my node is valid and alive. I have a same problem
on removeAttribute of MFnDependencyNode.
> I try to set undo to false. When undo is false delete node works as long
as outliner is not opened. When I open outliner maya crash...
>
>
> You have any solution ?

--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/
msgid/python_inside_maya/dc967374-6159-4702-ba6e-
77b9a12275d6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAFRtmODoo2hhPf9tC8Eth0LF1J2kFChtFN8ZLSdO9QhnO8oQOw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to