Motionbuilder 2018 Crash On Close

Recently I found time to do some Mobu quality of life work, and addressed a problem where one of our PySide tools was causing Mobu 2018 to crash on close. Whenever an animator or I closed Mobu with this tool open, the close dialog would hang at ‘Closing User Interface‘, and then crash without providing a log. I initially thought there was a stale callback in the scene that the tool didn’t clean up, but commenting out all of the callbacks that the tool created didn’t work. My debugger wasn’t catching the error either, so I really had to go through each step one-by-one to find the cause. I started by opening the tool and closing Mobu. Mobu closed just fine, so I then would open the tool, perform an operation in the tool, and close Mobu. Doing this a few times with different operations, I found that the problem was being caused by a QMenu containing embedded sub-menus was not cleaning itself up after it was created.

Before the fix:

# pseudocode
my_menu = QtGui.QMenu( 'my_menu', self.view )
my_menu.exec_( self.view.mapToGlobal( QPoint ) ) # Open menu

After the fix:

# pseudocode
my_menu = QtGui.QMenu( 'my_menu', self.view )
my_menu.exec_( self.view.mapToGlobal( QPoint ) ) # Open menu
my_menu.destroy( ) # Clean up the menu.

The only difference in these two blocks is the line ‘my_menu.destroy( )‘. The destroy( ) method cleaned up the QMenu and it’s sub-menus allowing Mobu to close properly. I believe you can also use QObject.deleteLater( ) to clean up menus after execution, but I’ll have to put that in practice to see the results.

Hope this helps!