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

Crash on macOS in QCocoaWindow::windowDidChangeScreen() when unplugging monitors

    XMLWordPrintable

Details

    • macOS

    Description

      Summary:

      An application compiled with Qt 5.12.1 occasionally crashes when unplugging the external monitors from a MacBookPro running on macOS 10.14.3.

       

      Steps to reproduce:

      1. I have a MacBookPro with a Thunderbolt Dock and 2 screens connected to the Dock.
      2. Run an application compiled with Qt 5.12.1
      3. Detach the Thunderbolt Dock from the MacBookPro

      Result: The application sometimes crashes.

       

      More information:

      The crash occurs in QCocoaWindow::windowDidChangeScreen():

      void QCocoaWindow::windowDidChangeScreen()
      {
          if (!window())
              return;
      
          const bool wasRunningDisplayLink = static_cast<QCocoaScreen *>(screen())->isRunningDisplayLink();
      

      Note the call to the function screen() which can return a nullptr:

      /*!
          Returns the platform screen handle corresponding to this platform window,
          or null if the window is not associated with a screen.
      */
      QPlatformScreen *QPlatformWindow::screen() const
      {
          QScreen *scr = window()->screen();
          return scr ? scr->handle() : nullptr;
      }
      

       

      Suggested fix:

      The QCocoaWindow::windowDidChangeScreen() function should check if screen() returns a nullptr pointer before using it. One possible fix would be to modify QCocoaWindow::windowDidChangeScreen() as follow:

      void QCocoaWindow::windowDidChangeScreen()
      {
          if (!window())
              return;
      
          if (!screen())
              return;
      
          const bool wasRunningDisplayLink = static_cast<QCocoaScreen *>(screen())->isRunningDisplayLink();
      
      

       

      Attachments

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

        Activity

          People

            vestbo Tor Arne Vestbø
            jirauser46068 user-e3f1a (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes