Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-3022

Encountering Random Crashes when using QQuickItem derived class with MouseEvents

    XMLWordPrintable

Details

    • Bug
    • Resolution: Cannot Reproduce
    • Not Evaluated
    • None
    • 6.6.2, 6.6.3.1, 6.7.3
    • PySide
    • None
    • Linux/X11, Windows

    Description

      We have an issue while implementing a QQuickItem derived component.

      The intent of the Custom QQuickItem derived component is to serve as a MouseArea along a defined path where only the clicks on the path are considered and any clicks outside can be ignored to be passed onto the other components.

      Issue: Clicking on the Custom Mouse Area causes the application to crash sometimes.

      Description: While the crash is triggered randomly, it is hard to say when the crash might occur, sometimes the crash doesn't happen before at least 200 clicks maybe and at times the crash can happen just after 10 clicks on the component.
      https://bugreports.qt.io/browse/PYSIDE-3022?filter=18899#
      The issue seems to be coming from the event instance which is being passed onto the derived class' mousePressEvent or mouseReleaseEvent, where queying the button() from the event results in a crash randomly.

      Even during the same function call, querying other attributes from the event seems to be working.

      e.g.

       

      event.position() // this works
      event.modifiers() // this works
      event.button() // crashes
      event.buttons() // crashes
      

       

      In the above examples, all of the methods were tried to be called in the same function call and the first two are giving correct output but the interpreter seems to crash when button() was invoked or buttons() was invoked at different times.

      GDB Trace for reference

       

      #0  0x00007f94362139bd in PyCallable_Check (x=0x7f93f4ea8e90) at Objects/object.c:1541
      #1  0x00007f93f4bf0f0d in ?? () from /dev/lib/python3.11/site-packages/PySide6/QtCore.abi3.so
      #2  0x00007f94361d605b in PyObject_SetAttr (v=0x7f934fc5f500, name=0x7f93d264d2b0, value=0x7f93f4ea8e90) at Objects/object.c:1028
      #3  0x00007f94361ed8c2 in _PyEval_EvalFrameDefault (tstate=<optimized out>, frame=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:2882
      #4  0x00007f943621420e in _PyEval_EvalFrame (throwflag=0, frame=0x7f9436788298, tstate=0x7f9436587698 <_PyRuntime+166328>) at ./Include/internal/pycore_ceval.h:73
      #5  _PyEval_Vector (kwnames=<optimized out>, argcount=2, args=0x7fff55741bb0, locals=0x0, func=0x7f93d27c9a80, tstate=0x7f9436587698 <_PyRuntime+166328>) at Python/ceval.c:6434
      #6  _PyFunction_Vectorcall (func=0x7f93d27c9a80, stack=0x7fff55741bb0, nargsf=<optimized out>, kwnames=<optimized out>) at Objects/call.c:393
      #7  0x00007f943621bb9c in _PyObject_FastCallDictTstate (kwargs=0x0, nargsf=<optimized out>, args=<optimized out>, callable=0x7f93d27c9a80, tstate=0x7f9436587698 <_PyRuntime+166328>) at Objects/call.c:141
      #8  _PyObject_Call_Prepend (kwargs=0x0, args=<optimized out>, obj=<optimized out>, callable=0x7f93d27c9a80, tstate=<optimized out>) at Objects/call.c:482
      #9  slot_tp_init (self=<optimized out>, args=<optimized out>, kwds=0x0) at Objects/typeobject.c:7855
      #10 0x00007f94361de8ab in type_call (kwds=0x0, args=0x7f934fb667d0, type=<optimized out>) at Objects/typeobject.c:1103
      #11 _PyObject_MakeTpCall (tstate=0x7f9436587698 <_PyRuntime+166328>, callable=0x2ad3c30, args=<optimized out>, nargs=<optimized out>, keywords=0x0) at Objects/call.c:214
      #12 0x00007f94361ea09f in _PyEval_EvalFrameDefault (tstate=<optimized out>, frame=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:4769
      #13 0x00007f94362344a6 in _PyEval_EvalFrame (throwflag=0, frame=0x7f9436788220, tstate=0x7f9436587698 <_PyRuntime+166328>) at ./Include/internal/pycore_ceval.h:73
      #14 _PyEval_Vector (kwnames=<optimized out>, argcount=<optimized out>, args=0x7fff55741e30, locals=0x0, func=0x7f93d27ca0c0, tstate=0x7f9436587698 <_PyRuntime+166328>) at Python/ceval.c:6434
      #15 _PyFunction_Vectorcall (kwnames=<optimized out>, nargsf=<optimized out>, stack=0x7fff55741e30, func=0x7f93d27ca0c0) at Objects/call.c:393
      #16 _PyObject_VectorcallTstate (kwnames=<optimized out>, nargsf=<optimized out>, args=0x7fff55741e30, callable=0x7f93d27ca0c0, tstate=0x7f9436587698 <_PyRuntime+166328>) at ./Include/internal/pycore_call.h:92
      #17 method_vectorcall (method=<optimized out>, args=<optimized out>, nargsf=<optimized out>, kwnames=<optimized out>) at Objects/classobject.c:89
      #18 0x00007f93edf717d2 in ?? () from /dev/lib/python3.11/site-packages/PySide6/QtQuick.abi3.so
      #19 0x00007f93ee5fa3b8 in QQuickItem::event (this=0x942a220, ev=0x7fff557426b0) at /dev/src/qt-everywhere-src-6.6.3/qtdeclarative/src/quick/items/qquickitem.cpp:8920
      #20 0x00007f93ec3931f2 in QApplicationPrivate::notify_helper (this=<optimized out>, receiver=0x942a220, e=0x7fff557426b0) at /dev/src/qt-everywhere-src-6.6.3/qtbase/src/widgets/kernel/qapplication.cpp:3296
      #21 0x00007f93f436592a in QCoreApplication::notifyInternal2 (receiver=0x942a220, event=0x7fff557426b0) at /dev/src/qt-everywhere-src-6.6.3/qtbase/src/corelib/kernel/qcoreapplication.cpp:1121
      #22 0x00007f93f4365aa9 in QCoreApplication::sendEvent (receiver=<optimized out>, event=<optimized out>) at /dev/src/qt-everywhere-src-6.6.3/qtbase/src/corelib/kernel/qcoreapplication.cpp:1539
      #23 0x00007f93ee76bd1b in QQuickDeliveryAgentPrivate::deliverMatchingPointsToItem (this=this@entry=0x1cfc450, item=0x942a220, isGrabber=isGrabber@entry=false, pointerEvent=pointerEvent@entry=0x7fff557426b0, handlersOnly=<optimized out>)
          at /dev/src/qt-everywhere-src-6.6.3/qtdeclarative/src/quick/util/qquickdeliveryagent.cpp:2192
      #24 0x00007f93ee76c97b in QQuickDeliveryAgentPrivate::deliverPressOrReleaseEvent (this=this@entry=0x1cfc450, event=event@entry=0x7fff557426b0, handlersOnly=handlersOnly@entry=false)
          at /dev/src/qt-everywhere-src-6.6.3/qtdeclarative/src/quick/util/qquickdeliveryagent.cpp:2141
      #25 0x00007f93ee76dcb0 in QQuickDeliveryAgentPrivate::deliverPointerEvent (this=0x1cfc450, event=event@entry=0x7fff557426b0) at /dev/src/qt-everywhere-src-6.6.3/qtdeclarative/src/quick/util/qquickdeliveryagent.cpp:1862
      #26 0x00007f93ee76ef5f in QQuickDeliveryAgentPrivate::handleMouseEvent (this=<optimized out>, event=event@entry=0x7fff557426b0) at /dev/src/qt-everywhere-src-6.6.3/qtdeclarative/src/quick/util/qquickdeliveryagent.cpp:1631
      #27 0x00007f93ee126905 in QQuickOverlay::eventFilter (this=0x32811a0, object=<optimized out>, event=0x7fff557426b0) at /dev/src/qt-everywhere-src-6.6.3/qtdeclarative/src/quicktemplates/qquickoverlay.cpp:545
      #28 0x00007f93f43656ca in QCoreApplicationPrivate::sendThroughObjectEventFilters (event=<optimized out>, receiver=<optimized out>) at /dev/src/qt-everywhere-src-6.6.3/qtbase/src/corelib/kernel/qcoreapplication.cpp:1253
      #29 QCoreApplicationPrivate::sendThroughObjectEventFilters (receiver=receiver@entry=0x233c720, event=event@entry=0x7fff557426b0) at /dev/src/qt-everywhere-src-6.6.3/qtbase/src/corelib/kernel/qcoreapplication.cpp:1242
      #30 0x00007f93ec3931e1 in QApplicationPrivate::notify_helper (this=<optimized out>, receiver=0x233c720, e=0x7fff557426b0) at /dev/src/qt-everywhere-src-6.6.3/qtbase/src/widgets/kernel/qapplication.cpp:3290
      #31 0x00007f93f436592a in QCoreApplication::notifyInternal2 (receiver=0x233c720, event=0x7fff557426b0) at /dev/src/qt-everywhere-src-6.6.3/qtbase/src/corelib/kernel/qcoreapplication.cpp:1121
      #32 0x00007f93f4365ab9 in QCoreApplication::sendSpontaneousEvent (receiver=<optimized out>, event=<optimized out>) at /dev/src/qt-everywhere-src-6.6.3/qtbase/src/corelib/kernel/qcoreapplication.cpp:1553
      #33 0x00007f93f01c20c0 in QGuiApplicationPrivate::processMouseEvent (e=0x7f930c005660) at /dev/src/qt-everywhere-src-6.6.3/qtbase/src/gui/kernel/qguiapplication.cpp:2325
      #34 0x00007f93f021868c in QWindowSystemInterface::sendWindowSystemEvents (flags=flags@entry=...) at /dev/src/qt-everywhere-src-6.6.3/qtbase/src/gui/kernel/qwindowsysteminterface.cpp:1109
      #35 0x00007f93e809e5ca in xcbSourceDispatch (source=<optimized out>) at /dev/src/qt-everywhere-src-6.6.3/qtbase/src/plugins/platforms/xcb/qxcbeventdispatcher.cpp:57
      #36 0x00007f93f1e73f4f in g_main_context_dispatch () from /dev/lib64/libglib-2.0.so.0
      #37 0x00007f93f1ec9268 in g_main_context_iterate.constprop () from /dev/lib64/libglib-2.0.so.0
      #38 0x00007f93f1e71713 in g_main_context_iteration () from /dev/lib64/libglib-2.0.so.0
      #39 0x00007f93f460984a in QEventDispatcherGlib::processEvents (this=0x2931490, flags=...) at /dev/src/qt-everywhere-src-6.6.3/qtbase/src/corelib/kernel/qeventdispatcher_glib.cpp:393
      #40 0x00007f93f4371283 in QEventLoop::exec (this=this@entry=0x7fff55742a90, flags=..., flags@entry=...) at /dev/src/qt-everywhere-src-6.6.3/qtbase/src/corelib/global/qflags.h:34
      #41 0x00007f93f436d9ce in QCoreApplication::exec () at /dev/src/qt-everywhere-src-6.6.3/qtbase/src/corelib/global/qflags.h:74
      #42 0x00007f93ecb87940 in ?? () from /dev/lib/python3.11/site-packages/PySide6/QtWidgets.abi3.so
      #43 0x00007f94360fef67 in cfunction_vectorcall_NOARGS (func=0x7f93ec009cb0, args=<optimized out>, nargsf=<optimized out>, kwnames=<optimized out>) at Objects/methodobject.c:486
      #44 0x00007f94361f8598 in _PyObject_VectorcallTstate (kwnames=<optimized out>, nargsf=<optimized out>, args=<optimized out>, callable=0x7f93ec009cb0, tstate=0x7f9436587698 <_PyRuntime+166328>) at ./Include/internal/pycore_call.h:92
      #45 PyObject_Vectorcall (callable=0x7f93ec009cb0, args=<optimized out>, nargsf=<optimized out>, kwnames=<optimized out>) at Objects/call.c:299
      #46 0x00007f94361ea09f in _PyEval_EvalFrameDefault (tstate=<optimized out>, frame=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:4769
      #47 0x00007f94362acea0 in _PyEval_EvalFrame (throwflag=0, frame=0x7f94367881b8, tstate=0x7f9436587698 <_PyRuntime+166328>) at ./Include/internal/pycore_ceval.h:73
      #48 _PyEval_Vector (tstate=tstate@entry=0x7f9436587698 <_PyRuntime+166328>, func=func@entry=0x7f9435f99120, locals=locals@entry=0x7f9428500380, args=args@entry=0x0, argcount=argcount@entry=0, kwnames=kwnames@entry=0x0) at Python/ceval.c:6434
      #49 0x00007f94362ac8ba in PyEval_EvalCode (co=<optimized out>, globals=0x7f9428500380, locals=<optimized out>) at Python/ceval.c:1148
      #50 0x00007f94362c5fad in builtin_exec_impl (module=<optimized out>, closure=<optimized out>, locals=0x7f9428500380, globals=0x7f9428500380, source=0x7f9428545580) at Python/bltinmodule.c:1077
      #51 builtin_exec (module=<optimized out>, args=<optimized out>, nargs=<optimized out>, kwnames=<optimized out>) at Python/clinic/bltinmodule.c.h:465
      #52 0x00007f94361f9436 in cfunction_vectorcall_FASTCALL_KEYWORDS (func=0x7f9435f88f90, args=0x7f9436788180, nargsf=<optimized out>, kwnames=0x0) at ./Include/cpython/methodobject.h:52
      #53 0x00007f94361f8598 in _PyObject_VectorcallTstate (kwnames=<optimized out>, nargsf=<optimized out>, args=<optimized out>, callable=0x7f9435f88f90, tstate=0x7f9436587698 <_PyRuntime+166328>) at ./Include/internal/pycore_call.h:92
      #54 PyObject_Vectorcall (callable=0x7f9435f88f90, args=<optimized out>, nargsf=<optimized out>, kwnames=<optimized out>) at Objects/call.c:299
      #55 0x00007f94361ea09f in _PyEval_EvalFrameDefault (tstate=<optimized out>, frame=<optimized out>, throwflag=<optimized out>) at Python/ceval.c:4769
      #56 0x00007f943621420e in _PyEval_EvalFrame (throwflag=0, frame=0x7f9436788020, tstate=0x7f9436587698 <_PyRuntime+166328>) at ./Include/internal/pycore_ceval.h:73
      #57 _PyEval_Vector (kwnames=<optimized out>, argcount=2, args=0x7f94285a4a98, locals=0x0, func=0x7f94285b6f20, tstate=0x7f9436587698 <_PyRuntime+166328>) at Python/ceval.c:6434
      #58 _PyFunction_Vectorcall (func=0x7f94285b6f20, stack=0x7f94285a4a98, nargsf=<optimized out>, kwnames=<optimized out>) at Objects/call.c:393
      #59 0x00007f94362d8c79 in pymain_run_module (modname=modname@entry=0x7f9436365840 L"__main__", set_argv0=set_argv0@entry=0) at Modules/main.c:300
      #60 0x00007f943613625c in pymain_run_python (exitcode=0x7fff557430a4) at Modules/main.c:602
      #61 Py_RunMain () at Modules/main.c:684
      #62 0x00007f943629cde9 in Py_BytesMain (argc=<optimized out>, argv=<optimized out>) at Modules/main.c:738
      #63 0x00007f9435c295d0 in __libc_start_call_main () from /lib64/libc.so.6
      #64 0x00007f9435c29680 in __libc_start_main_impl () from /lib64/libc.so.6
      

       

      As per the trace, I guess it seems to be breaking here https://github.com/python/cpython/blob/v3.11.10/Objects/object.c#L1541

      Possibly the Py_TYPE is null, but that could mean a lot of things.

      The issues are reproducible in the below combination of Versions

      Qt 6.6.3 | PySide 6.6.3 | Python 3.9

      Qt 6.6.3 | PySide 6.6.3 | Python 3.11

      Qt 6.7.3 | PySide 6.7.3 | Python 3.9

       

      Although we have a usual complex usage of the functionality, but the crash issue can be reproduced using a very simple example where we have a flat CustomMouseArea inheriting from QQuickItem and used as a header for a basic draggable Node kind,

      Please find attached the simplest example which can cause a crash.

      Steps to Reproduce the crash on the Basic Example:

        • Launch the python script*
        • Click on the blue header couple of times (The Blue header holds the custom MouseArea)*
        • Randomly move the node kind around by clicking and dragging the green area*
        • Click on the blue header couple of times more*
        • Maybe alternate between right and left clicks few times*
        • Repeat the move and click and alternations process multiple times and it is eventually going to crash*
        • It is very hard to say when the crash might occur, but sometimes the crash is quicker while other times the crash can take a bit of time*

       

      Debug Log from Python:

       

      :RELEASED:MouseButton.LeftButton
      :PRESSED:MouseButton.LeftButton
      qml: QVariant(PySide::PyObjectWrapper, 0x7ff71fe8ab30)
      :RELEASED:MouseButton.LeftButton
      :PRESSED:MouseButton.LeftButton
      qml: QVariant(PySide::PyObjectWrapper, 0x7ff71fe8ab30)
      Fatal Python error: Segmentation fault
       
      Current thread 0x00007ff761637b80 (most recent call first):
        File "/dev/test/qmtest.py", line 39 in mouseReleaseEvent
        File "/dev/test/qmtest.py", line 56 in <module>
      Segmentation fault
      

      In the above log, the trace points to the same line 39 which is indeed printing the evt.button() as per the shared examples.

      Attachments

        1. pyside3022.zip
          2 kB
        2. qmtest.py
          2 kB
        3. test.qml
          2 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            waaake Vivek Verma
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes