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

Black screen and crash after going to foreground with events in the queue generated in background

    XMLWordPrintable

Details

    • Android
    • 2022wk26FOQtforAndroid, 2023wk40FOQtforAndroid, 2023wk44FOQtforAndroid, 2023wk46FOQtforAndroid, 2023wk50FOQtforAndroid, 2023wk52FOQtforAndroid, 2024wk02FOQtforAndroid

    Description

      The problem was observed on Android 11 and 12, Android 10 seems to work as expected.

      When the Android app goes to background, the events from the main ui thread's queue are not processed. But some other threads and event loops can still operate, generate events and put them in main ui thread's event loop. Those events should be properly consumed when the app goes back to foreground and main thread is resumed. The attached sample apps reproduce such situation in two different ways.

      The crash happens when some background thread generates events intended to be consumed by the main ui thread. The event handler on the qml side must change the UI state.

      Two scenarios has been tested, in both of them it's easy to end up with crash:

      • events are generated by some c++ worker run in a separate thread, communicating with the qml gui via signals/slots.
      • events are generated using WorkerScript, no C++ code is involved

      The crash was observed when qml handler was modifying gui in a following way:

      • items added to the model used by ListView or GridView
      • items added to the model used by Repeater or Instantiator
      • items are created using Component.createObject() and displayed on the scene

      After going back to foreground for the first time there is a black screen. The second attempt ends up with a segfault.

      Attachments

        1. android_crash.webm
          21.96 MB
        2. anr_2023-09-18-12-46-11-951
          1.09 MB
        3. CppWorkerExample.zip
          4 kB
        4. WorkerScriptExample-1.zip
          2 kB

        Issue Links

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

          Activity

            People

              petri.virkkunen Petri Virkkunen
              mcieslak Michał Cieślak
              Votes:
              6 Vote for this issue
              Watchers:
              10 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes