Prevent Maya crashing along with PySide widget

Hi!
I am building a character picker using pySide, it’s working OK so far apart from crashing Maya each time it encounters an exception such as an attribute error.

I am using MayaMix and wrapInstance for this just to add some more info.

Now, here’s my question, is there a way to prevent this from happening? I don’t mind the Qt ui crashing but if it’s crashing Maya each time it gets an exception then the picker is useless. There are some error-handling code in the C++ docs but I cannot find the pySide equivalents. Thanks in advance.

Do you have an example of something that crashes? Exceptions normally don’t crash Maya. There might be something else going on.

Hello.
Thanks for replying. I don’t have the code at home and tomorrow is a holiday so the only thing I can say now is it crashes at times when I refresh the GUI, “Attribute Error” is the usual error before everything dies. I will try and isolate it as soon as I can. I hope that there’s a better error-catching mechanism available to me.

Yeah I agree with @marcuso a simple exception shouldn’t be crashing Maya.
PySide does have some instances where the C++ objects and python objects can get out of sync, but they don’t generally cause an AttributeError before blowing up.

Thanks. This character picker is probably the most complicated that I have made so thats probably causing it. simpler GUIs are OK so far. weird…

So one thing to look for is instances where you’re passing some kind of QObject to a method directly instead of binding it to a name.

stuff like: widget.setSomething(SomeObject())
vs

so = SomeObject()
widget.setSomething(so)

Stuff like that can cause issues where the python garbage collector tries to clean up an object that is still needed on the C++ side or vice versa. As python and Qt have different behaviors when it comes to object lifetimes.

Thanks! I will surely try that in the coming days. I was hoping that there’s a definitive pySide/pyQt resource available but I cannot find anything. its a good thing that I dont need to touch it as much.

OK. this is odd. I havent had a crash yet when running the thing in Maya 2018…

I think I have isolated the problem. I will update you guys if I find something. really annoying how maya just dies without giving an error.

OK, spent the whole day cleaning up the code but still crashes maya when it encounters a Fatal exception. :frowning:

I really can’t help you without seeing what your code looks like, but if you’re using anything that docks you may want to try another method and see if the crash goes away. The docking behavior was overhauled between Maya 2016 and Maya 2017 (dock control replaced with workspace control). I had all kinds of stability problems because of it so it may be worth checking out. May or may not help your situation

thanks, everyone.

I think I have isolated the problem and it has nothing to do with the code!

this only happens at times when the network drive is slow…weird…

import traceback
try:

     <block of code>

except:

    traceback.print_exc()

Suppresses the error but still prints it for debugging.
It isn’t ideal and should only be used in random cases where getting the traceback is either suppressed ( this happens a lot in 3DsMax ) or your DCC is expected to crash ( also relatively common in 3DsMax ).

Thanks. I was forced to do that. multiple ones of every major part of the code with exception printing.

I have traced it to compiling. our Maya installation has lots of crazy code pinging the network and it freezes when it didn’t get a ping-back. seriously want to overhaul the whole system one of these days.