Hi all,
I’m trying to figure out convert a crash into an exception.
The crash is coming from use of a function set when the MObject it’s managing is pointing to a node I’ve just deleted. Here’s the shortest I could make of it (Maya 2018).
from maya.api import OpenMaya as om
fn = om.MFnDagNode()
mobj = fn.create("transform")
fn.name()
# u'transform3'
mod = om.MDGModifier()
mod.deleteNode(mobj);
mod.doIt();
del mod
fn.name()
Which throws this..
Stack trace:
Foundation.dll!TmtRefCounter::add
Foundation.dll!Tstring::operator=
OpenMaya.dll!Autodesk::Maya::OpenMaya20180000::MString::operator=
OpenMaya.dll!Autodesk::Maya::OpenMaya20180000::MFnDependencyNode::name
OpenMaya.dll!MPyMFnDependencyNode_Type::addToModule
python27.dll!PyEval_GetFuncDesc
python27.dll!PyEval_EvalFrameEx
python27.dll!PyEval_EvalCodeEx
python27.dll!PyRun_FileExFlags
python27.dll!PyRun_InteractiveOneFlags
python27.dll!PyRun_InteractiveLoopFlags
python27.dll!PyRun_AnyFileExFlags
python27.dll!Py_Main
KERNEL32.DLL!BaseThreadInitThunk
ntdll.dll!RtlUserThreadStart
Result: untitled
Fatal Error. Attempting to save in C:/Users/marcus/AppData/Local/Temp/marcus.20180103.0935.ma
The fact that it crashes isn’t a problem, it makes sense. But what I’d like to try and do is instead of having it crash raise an exception.
I went for MObject.isNull() at first, but that seems to always return False.
Any ideas?
Best,
Marcus
--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOBw42L51ULyNjOCmKGMOJTcnw44w-r5VjPMocLbpj%2BhfA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOBw42L51ULyNjOCmKGMOJTcnw44w-r5VjPMocLbpj%2BhfA%40mail.gmail.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 python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAAssL7bFoewtSBQo%2B9kzNwbSo9YOKJ_ftZp5L_qzHHi0YBSX1Q%40mail.gmail.com.
# Delete nodemdg_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_modLooks like you’ve just uncovered a bug in maya. I say this because if I comment out the “del mdg_mod” line:
import pymel.core as pm
import maya.OpenMaya as OpenMaya
handles_to_delete = []
for i in xrange(5):
new_nodes = pm.polyCube()
for new_node in new_nodes:
handles_to_delete.append(new_node.__apihandle__())
old_undo_state = pm.undoInfo(q=1, state=1)
pm.undoInfo(state=0)
try:
mdg_mod = OpenMaya.MDGModifier()
for moh_node in handles_to_delete:
if moh_node.isValid() is False:
continue
mdg_mod.deleteNode(moh_node.object())
mdg_mod.doIt()
# del mdg_mod
finally:
pm.undoInfo(state=old_undo_state)
…then it no longer crashes… however, the viewport still displays the now-deleted cube(s), even though they don’t exist in the outliner / scene / etc. Clearly a bug - the viewport is still keeping around references to deleted objects somehow. (Tested with 2018.1, don’t have a copy of 2018.2 yet.)
Not much to do other than submit a bug report to autodesk about it.
Also - if possible, please try to include independently-executable code samples when you’re looking for help troubleshooting. It makes it much more likely you’ll get help… frequently, if I see something like “self.a_roots” in a code snippet, I won’t even bother trying to troubleshoot.
--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/1e10760b-b977-4d7f-a088-3132d46d6b0c%40googlegroups.com.
--
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 python_inside_maya+unsub...@googlegroups.com.To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/dc967374-6159-4702-ba6e-77b9a12275d6%40googlegroups.com.
I managed to use MObjectHandle to avoid a crash successfully.
from maya.api import OpenMaya as om
fn = om.MFnDagNode()
mobj = om.MObjectHandle(fn.create("transform"))
mobj.isAlive()
# True
fn.name()
# u'transform3'
mod = om.MDGModifier()
mod.deleteNode(mobj.object())
mod.doIt()
mobj.isAlive()
del mod
fn.name()
# ''
mobj.isAlive()
# False
Testing this in production next.
It’s not possible to show my code because I experiment a new automatic rig. It’s not I don’t want to show my code but I have lot of file and is not possible to post all here…
I’ll try to do some code to show when maya crash but I do not promise that I will get there with all my code…
There’s no need to post all of your code, the trick is providing a short reproduction of the problem, such that we can run it ourselves. The fact that you’re reading a JSON and are making a rig etc. is likely not related to the problem and can be left out. The code snippet I provided (for example) isn’t actually part of anything I use in production, but rather is a condensed version highlighting the problem. Solving this condensed problem solves the problem in my production code.
--
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 python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/47a297ad-811a-49a2-8c0e-8b50381fcefa%40googlegroups.com.
There’s no need to post all of your code, the trick is providing a short reproduction of the problem, such that we can run it ourselves. The fact that you’re reading a JSON and are making a rig etc. is likely not related to the problem and can be left out. The code snippet I provided (for example) isn’t actually part of anything I use in production, but rather is a condensed version highlighting the problem. Solving this condensed problem solves the problem in my production code.....Missed to include a key highlight, the isAlive() returns True before del mod, suggesting that it isn’t deleted internally until the modifier has been garbage collected.
Does my example posted about also cause a crash for you ?
--
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 python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/9c5d8b62-fa95-453d-8345-1724f8912fca%40googlegroups.com.
What do you prefere with this API ?
Well, for one, I like that it doesn’t crash when I run the snippet above. :)