casting MPlugArray into a list don't hold the MPlugs in memory?

18 views
Skip to first unread message

Rudi Hammad

unread,
Jan 19, 2022, 12:35:37 PM1/19/22
to Python Programming for Autodesk Maya
hello,

I though about sharing someting strange that occured to me. I had a method that contained
MPlug.destinations() which as an art requieres an MPlugArray(). For some reason, probably because I was in a hurry and I didn't thought about it, I casted all the MPlugs from MPlug.destinations() into a python list. Let's call it foo=list().
And that's where I started getting crashes. For instance, if I did something like
foo[0], which is supposed to hold an MPlug, maya return the MPlug okey, but if I did foo[0].isNull() it returned True and then crashed.

Whereas if you don't use a python list,  and query directly the MPlugArray  (e.g, myMPlugArr[0].isNull) it returns False and everything is ok.

So my question more out curiosity than anything else. I know python lists are mutable objects, but not sure how or if that could be related.

Cheers,
R

Justin Israel

unread,
Jan 19, 2022, 1:01:28 PM1/19/22
to python_in...@googlegroups.com
If foo[0] gives you an object, but foo[0].isNull() crashes, then it could be a bug in the C++ wrapper and how it reference counts. Does it crash if you first save the object in a variable? 
    p = foo[0]
    p.isNull()
I think either way it may be a bug in the wrappers around the C++ memory and the reference counting. 


--
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/62002c0d-0c72-43d0-9bd8-5e845d3d43b2n%40googlegroups.com.

Rudi Hammad

unread,
Jan 19, 2022, 1:34:25 PM1/19/22
to Python Programming for Autodesk Maya
yes, it does crash if you save the object in the variable. But it depends on how many times you run p.isNull(). I executed that in maya's script editor around 6 or 7 times without crash.
But it crashed at the 8th time or so. What I find strange is that the list actually holds the MPlugs, but they become null. Maybe that's why they did the MPlugArray for MPlug.destinations()??
Anyways, after almost getting a nervious break down I realised that it was coming from there XD. I just spent around 3 hours trying to figure it out. Also I tried to read the MayaCrashLog.log file
and it was like reading Klingon. No idea how to underst what it says.
Reply all
Reply to author
Forward
0 new messages