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

Crash on exit in destroySufrace when app is stopped from OS (Activity.stop)

    XMLWordPrintable

Details

    • Android

    Description

      Found this random crash when app is thrown out of the recent apps list or when using Android Developer options => "Don't keep Activities" and hitting Home button. The app is killed with "JNI DETECTED ERROR IN APPLICATION ... use of deleted global ref 0x....".

      The point of the crash:

      androidjnimain.cpp:

      void destroySurface(int surfaceId)
      ....
                   env->CallStaticVoidMethod(m_applicationClass,
                                            m_destroySurfaceMethodID,
                                            surfaceId);

      Turns out that this may be somehow executed after terminateQt when m_applicationClass is already deleted.
      A rude hotfix is:
      In terminateQt():

      ...
          env->DeleteGlobalRef(m_applicationClass);
          m_applicationClass = nullptr; // Add this line
      ...

      In destroySurface:

              QJNIEnvironmentPrivate env;
              if (env && m_applicationClass) // Add check for m_applicationClass here
                  env->CallStaticVoidMethod(m_applicationClass,
                                           m_destroySurfaceMethodID,
                                           surfaceId);

      However, it is probably not the best way to fix.

      IMO the best idea is to remove call for terminateQt from Java and call it in a global scope guard so the JNI references will stay alive until static deinitialization of the libraries.

      Attachments

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

        Activity

          People

            qtandroidteam Qt Android Team
            tl1 Sergey Galin
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes