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

Qt 5.15 + iOS 16: Repeatedly creating and deleting a Camera can eventually cause a crash with EXC_BAD_ACCESS

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P1: Critical
    • None
    • 5.15.13
    • Multimedia
    • XCode 14.3, iOS 16.4 SDK, iPad Air 5th Gen running iOS 16.1.1
    • iOS/tvOS/watchOS

    Description

      Code

      CameraView.qml

      import QtQuick 2.15
      import QtQuick.Controls 2.15
      import QtMultimedia 5.15
      
      Rectangle {
          color: "black"
      
          VideoOutput {
              id: viewfinder
              anchors.fill: parent
              fillMode: VideoOutput.PreserveAspectFit
              source: camera
              autoOrientation: true
          }
      
          Camera {
              id: camera
              deviceId: QtMultimedia.availableCameras.length > 0 ? QtMultimedia.availableCameras[0].deviceId : ""
              captureMode: Camera.CaptureStillImage
              cameraState: Camera.UnloadedState
          }
      
          // The presence of this BusyIndicator seems to increase crash frequency
          BusyIndicator {
              id: busy
              anchors.centerIn: parent
              width: 60
              height: 60
          }
      
          function startCamera() {
              if (QtMultimedia.availableCameras.length > 0)
                  camera.start()
              else
                  console.log("No cameras available!")
          }
      
          function stopCamera() {
              camera.stop()
          }
      }
      

       

      main.qml

      import QtQuick 2.15
      import QtQuick.Controls 2.15
      
      ApplicationWindow {
          width: 800
          height: 480
          visible: true
      
          property int iterationsRemaining: 0
          property bool testRunning: iterationsRemaining > 0
      
          Button {
              anchors.centerIn: parent
              enabled: !testRunning
              text: "Start Test"
              onClicked: {
                  iterationsRemaining = 50
                  startTimer.start()
              }
          }
      
          Loader {
              id: camLoader
              anchors.fill: parent
              source: "CameraView.qml"
              active: false
          }
      
          Timer {
              id: startTimer
              repeat: iterationsRemaining > 0
              interval: 2000
              running: false
              triggeredOnStart: true
              onTriggered: {
                  --iterationsRemaining
                  console.log("Test iterations remaining:", iterationsRemaining)
                  camLoader.active = true
                  camLoader.item.startCamera()
                  stopTimer.start()
              }
          }
      
          Timer {
              id: stopTimer
              repeat: false
              interval: 500
              running: false
              onTriggered: {
                  camLoader.item.stopCamera()
                  camLoader.active = false
              }
          }
      }
      

       

      Steps to reproduce

      1. Build and run the attached project on a physical iOS device
      2. Tap "Start Test" and wait for the crash (give camera permissions when asked)
      3. If it doesn't crash within 50 iterations, close + restart the app and tap "Start Test" again

       

      Notes

      • The number of iterations required to trigger the crash is variable
      • For some reason, adding the BusyIndicator seems to increase crash frequency
      • This does not seem to affect iOS 15 and earlier

      Attachments

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

        Activity

          People

            tpochep Timur Pocheptsov
            skoh-qt Sze Howe Koh
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There is 1 open Gerrit change