On Sun, Sep 2, 2018, 10:06 AM James Porter <[email protected]> wrote:

> Hey guys,
>
> I’m running the latest Maya 2018 on MacOS.
>
> I can import PySide2 it’s libraries without any hassle. However, whenever
> I attempt to load a basic gui (like the code below), Maya freezes and
> crashes. Anyone else experienced this? Anyone know how to fix it?
>
> Cheers
>
> James
>
>
> Basic code (I took this from
> https://github.com/mad-guru/maya/blob/master/_UI_sample):
>
> import maya.cmds as cmds
> import maya.mel as mel
> import pymel.core as pm
> class className():
> def __init__(self):
> self.varA = 1
> self.varB = 2
> self.varC = None
> def definitionA(self):
> self.varC=self.varA+self.varB
> def definitionB(self, userName):
> if self.varC==None:
> return
> print ('Hi '+ userName + ', thanks for visiting.')
> print ('varC is equal to '+str(self.varC))
> # creates instance of this class
> cn = className()
> ####################################
> # GUI ##############################
> ####################################
> # srinikom.github.io/pyside-docs/
> from PySide2 import QtGui
> from PySide2 import QtWidgets
> from functools import partial
> import maya.OpenMayaUI as mui
> import shiboken2
> def getMayaWindow():
> pointer = mui.MQtUtil.mainWindow()
> return shiboken2.wrapInstance(long(pointer), QtWidgets.QWidget)
> # def className_U1():
> objectName = 'pyMyWin'
> # check for existing window
> if cmds.window("pyMyWin", exists=True):
> cmds.deleteUI("pyMyWin", wnd=True)
> # create a window
> parent = getMayaWindow()
> window = QtWidgets.QMainWindow(parent)
> window.setObjectName(objectName)
> # create font
> font = QtGui.QFont()
> font.setPointSize(12)
> font.setBold(True)
> # create a widget
> widget = QtWidgets.QWidget()
> window.setCentralWidget(widget)
> # create a layout
> layout = QtWidgets.QVBoxLayout(widget) # horizontal QtGui.QHBoxLayout()
> # create buttons
> # imagePath = cmds/internalVar(upd=True)+'icons/blue_field_background.png'
> # button.setStylesheet("background-image: url("+1magePath+"); border:solid
> black 1px;color.rgb(0,0,0)")
> # A+B button
> button = QtWidgets.QPushButton("A + B")
> layout.addWidget(button)
> button.setFont(font)
> button.setMinimumSize(200, 40)
> button.setMaximumSize(200, 40)
> button.setStyleSheet("background-color: rgb(128,128,128); color:
> rgb(0,0,0)")
> button.clicked.connect(partial(cn.definitionA))
> #C button
> button = QtWidgets.QPushButton("Print C")
> layout.addWidget(button)
> button.setFont(font)
> button.setMinimumSize(200, 40)
> button.setMaximumSize(200, 40)
> button.setStyleSheet("background-color: rgb(128,128,128); color:
> rgb(0,0,0)")
> button.clicked.connect(partial(cn.definitionB,'Adnan'))
> # create close button
> closeButton = QtWidgets.QPushButton('Close')
> layout.addWidget(closeButton)
> closeButton.setFont(font)
> closeButton.clicked.connect(window.close)
> # show the window
> window.show()
>
>
>
> As I ran Maya from a terminal, I’ve managed to get the following info from
> it (this is from the moment of running Maya)
>

>
> objc[2591]: Class RunLoopModeTracker is implemented in both
> /Applications/Autodesk/maya2018/Maya.app/Contents/MacOS/libQt5Core.5.dylib
> (0x10a4eef38) and
> /Library/Python/2.7/site-packages/PySide2/Qt/lib/QtCore.framework/Versions/5/QtCore
> (0x12e41d010). One of the two will be used. Which one is undefined.
>
> objc[2591]: Class NotificationReceiver is implemented in both
> /Applications/Autodesk/maya2018/Maya.app/Contents/MacOS/libQt5Widgets.5.dylib
> (0x10aad79b8) and
> /Library/Python/2.7/site-packages/PySide2/Qt/lib/QtWidgets.framework/Versions/5/QtWidgets
> (0x12d45a238). One of the two will be used. Which one is undefined.
>
> *** Recognized (0x69) family*** (30 cols X 22 rows)
>
> Initialized VP2.0 renderer {
>
>   Version : 2016.11.40.12. Feature Level 5.
>
>   Adapter : AMD Radeon Pro 560 OpenGL Engine
>
>   Vendor ID: 4098. Device ID : 0x67EF
>
>   Driver : 4.1 ATI-1.68.20.
>
>   API : OpenGL V.4.1.
>
>   Max texture size : 16384 * 16384.
>
>   Max tex coords : 32
>
>   Shader versions supported (Vertex: 5, Geometry: 5, Pixel 5).
>
>   Shader compiler profile : (Best card profile)
>
>   Active stereo support available : 0
>
>   GPU Memory Limit : 4096 MB.
>
>   CPU Memory Limit: 15564.8 MB.
>
> }
>
> OpenCL evaluator is attempting to initialize OpenCL.
>
> Detected 1 OpenCL Platforms:
>
>  0: Apple. Apple. OpenCL 1.2 (May 24 2018 20:07:03).
>
>  Supported extensions: cl_APPLE_SetMemObjectDestructor
> cl_APPLE_ContextLoggingFunctions cl_APPLE_clut cl_APPLE_query_kernel_names
> cl_APPLE_gl_sharing cl_khr_gl_event
>
> OpenCL evaluator choosing OpenCL platform Apple.
>
> 10136
>
> Choosing OpenCL Device AMD Radeon Pro 560 Compute Engine.  Device Type:
> GPU  Device is available.
>
>
> Launching SSO process with command line: /Library/Application
> Support/Autodesk/AdSSO/AdSSO-v2.app/Contents/MacOS/AdSSO-v2 --process_name
> Autodesk.SSO.DefaultProcess-v2 --server_name Autodesk.SSO.DefaultServer-v2
>
>
> QWidget: Must construct a QApplication before a QWidget
>
> Stack trace:
>
>   4   libsystem_kernel.dylib              0x00007fff7f971b66
> __pthread_kill + 10
>
>   5   libsystem_c.dylib                   0x00007fff7f8cd1ae abort + 127
>
>   6   QtCore                              0x000000012df5af29
> QMessageLogger::debug(char const*, ...) const + 361
>
>   7   QtCore                              0x000000012df5c8a0
> QMessageLogger::fatal(char const*, ...) const + 224
>
>   8   QtWidgets                           0x000000012d012d2b
> QWidgetPrivate::QWidgetPrivate(int) + 587
>
>   9   QtWidgets                           0x000000012d147d6e
> QMainWindow::QMainWindow(QWidget*, QFlags<Qt::WindowType>) + 46
>
>   10  QtWidgets.so                        0x000000012c8be54c
> Sbk_QMainWindow_Init(_object*, _object*, _object*) + 668
>
>   11  Python                              0x000000010f477ea5 type_call +
> 245
>
>   12  Python                              0x000000010f40e442 PyObject_Call
> + 98
>
>   13  Python                              0x000000010f4c1c73
> PyEval_EvalFrameEx + 10259
>
>   14  Python                              0x000000010f4c9ff3
> PyEval_EvalCodeEx + 2131
>
>   15  Python                              0x000000010f4ca116
> PyEval_EvalCode + 54
>
>   16  libCommandEngine.dylib              0x0000000101dcf410
> TpythonInterpreter::executeCommand(Tstring const&, bool, bool,
> TinterpreterResult*) + 784
>
>   17  libExtensionLayer.dylib             0x0000000102ac79c0
> QmayaCommandScrollField::createMimeDataFromSelection() const + 1168
>
>   18  libExtensionLayer.dylib             0x0000000102a67832
> TidleAction::preDoIdleAction(Tevent const&) + 18
>
>   19  libExtensionLayer.dylib             0x0000000102a67757
> TidleDeviceHandlerAction::serverDeleted(TclientServer*, TserverMsg const&)
> + 343
>
>   20  libExtensionLayer.dylib             0x0000000102a7a363
> TeventHandler::doIdles() + 675
>
>   21  libExtensionLayer.dylib             0x0000000102a79fdc
> TidleTrigger::removeClientHook(Tclient*, Tmetaclass*) + 4092
>
>   22  libQt5Core.5.dylib                  0x000000010a1d55a0
> QObject::event(QEvent*) + 48
>
>   23  libExtensionLayer.dylib             0x0000000102a79f1f
> TidleTrigger::removeClientHook(Tclient*, Tmetaclass*) + 3903
>
>   24  libQt5Widgets.5.dylib               0x000000010a5b4c56
> QApplicationPrivate::notify_helper(QObject*, QEvent*) + 294
>
>   25  libQt5Widgets.5.dylib               0x000000010a5b81ce
> QApplication::notify(QObject*, QEvent*) + 8558
>
>   26  libExtensionLayer.dylib             0x0000000102a6fa2a
> QmayaApplication::currentMousePos() + 4218
>
>   27  libQt5Core.5.dylib                  0x000000010a1a8c07
> QCoreApplication::notifyInternal2(QObject*, QEvent*) + 167
>
>   28  libQt5Core.5.dylib                  0x000000010a200ab1
> QTimerInfoList::activateTimers() + 1329
>
>   29  libqcocoa.dylib                     0x00000001235b7e82
> QCocoaEventDispatcherPrivate::activateTimersSourceCallback(void*) + 18
>
>   30  CoreFoundation                      0x00007fff579fea11
> __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
>
>   31  CoreFoundation                      0x00007fff57ab842c
> __CFRunLoopDoSource0 + 108
>
>   32  CoreFoundation                      0x00007fff579e1470
> __CFRunLoopDoSources0 + 208
>
>   33  CoreFoundation                      0x00007fff579e08ed
> __CFRunLoopRun + 1293
>
>   34  CoreFoundation                      0x00007fff579e0153
> CFRunLoopRunSpecific + 483
>
>   35  HIToolbox                           0x00007fff56ccad96
> RunCurrentEventLoopInMode + 286
>
>   36  HIToolbox                           0x00007fff56ccab06
> ReceiveNextEventCommon + 613
>
>   37  HIToolbox                           0x00007fff56cca884
> _BlockUntilNextEventMatchingListInModeWithFilter + 64
>
>   38  AppKit                              0x00007fff54f7ba73 _DPSNextEvent
> + 2085
>
>   39  AppKit                              0x00007fff55711e34
> -[NSApplication(NSEvent)
> _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 3044
>
>   40  AppKit                              0x00007fff54f70885
> -[NSApplication run] + 764
>
>   41  libqcocoa.dylib                     0x00000001235b8aad
> QCocoaEventDispatcher::processEvents(QFlags<QEventLoop::ProcessEventsFlag>)
> + 2205
>
>   42  libQt5Core.5.dylib                  0x000000010a1a4f31
> QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) + 401
>
>   43  libQt5Core.5.dylib                  0x000000010a1a92ea
> QCoreApplication::exec() + 346
>
>
> Fatal Error. Attempting to save in
> /var/folders/34/y46587hs3q34swhhkl0fblcc0000gn/T/james.20180902.1004.maWriting
> crash report in
> /var/folders/34/y46587hs3q34swhhkl0fblcc0000gn/T/james.20180902.1004.crash
>
>
>
This crash is expected if you are running that example code from a
terminal. Qt applications always need a QApplication instance to be created
first, and to then exec it to start the event loop. When you are inside the
Maya UI there is already an instance of QApplication running so you don't
have to do it yourself. So that bring said, have you tested this code from
the Maya Script Editor?

In this terminal output, you can also see that it is warning you that it is
picking up your system PySide2, causing it to load two versions of Qt5.
This is also a potential for crashing once you get beyond the problem of
not having created a QApplication in the terminal. You have to make sure
you pick up Maya's PySide2 first.

-- 
> 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/CACsi_51r%3DYSzYM2WxfujE_vD4MHNGbLgKNNZ9050AqjT28%2BHuA%40mail.gmail.com
> <https://groups.google.com/d/msgid/python_inside_maya/CACsi_51r%3DYSzYM2WxfujE_vD4MHNGbLgKNNZ9050AqjT28%2BHuA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> 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/CAPGFgA3ct5RP7%2BY_5LBHU5%2B%2BOzq1xMpDGX2%3D2BCHbm1gTebYrQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to