Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-133576

Segmentation Fault on macOS when closing QGraphicsView after drag gesture

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P1: Critical
    • None
    • 6.8.0
    • Widgets: GraphicsView
    • None

    Description

      Issue

      On macOS, when using QGraphicsView, performing a drag gesture inside the view and then closing the application causes a segmentation fault.

      Steps to reproduce

      1. Run the following minimal example:
        from PyQt6.QtWidgets import QApplication, QGraphicsView
        app = QApplication([])
        v = QGraphicsView()
        v.show()
        app.exec()
         
      2. Drag inside the QGraphicsView window.
      3. Close the window.

      Expected behavior

      The application should exit cleanly without crashing.

      Actual behavior

      A segmentation fault occurs, and the following crash log is generated:
      Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
      0 libqcocoa.dylib 0x104351a94 0x1042f8000 + 367252
      1 AppKit 0x1973cab5c -[NSTouch dealloc] + 48
      2 CoreFoundation 0x1935987b0 {}RELEASE_OBJECTS_IN_THE_SET{} + 148
      3 CoreFoundation 0x1935986cc -[__NSSetM dealloc] + 148
      4 AppKit 0x1972842a4 -[NSEvent dealloc] + 68
      5 libqcocoa.dylib 0x10430d3c4 0x1042f8000 + 86980
      ...

      Workaround

      A temporary workaround that prevents the crash is to use app.aboutToQuit.connect(safe_exit), as shown below:
      from PyQt6.QtWidgets import QApplication, QGraphicsView

      app = QApplication([])
      v = QGraphicsView()
      v.show()

      def safe_exit():
          for _ in range(5):
              app.processEvents()

      app.aboutToQuit.connect(safe_exit)
      app.exec()
       
      This suggests that the issue might be related to improper cleanup of macOS touch events when QGraphicsView is destroyed.

      Environment

      • Qt Version: 6.8.0
      • macOS Version: 15.3
      • Python Version: 3.12.8
      • PyQt Version: 6.8.0
      • Installation Method: pip install PyQt6

      Additional Notes

      This issue does not occur on Windows or Linux, only on macOS.
      It is likely related to libqcocoa.dylib and how macOS touch events are handled.

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            bibr Andreas Aardal Hanssen
            bravotan Keisuke Urago
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes