diff options
author | Alex Blasche <alexander.blasche@digia.com> | 2014-03-04 16:17:09 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-03-11 10:59:16 +0100 |
commit | 2d2dbd3199a10985c713e97d32688e001e4cb226 (patch) | |
tree | 62e1e34a4507d218ce58f9659c17e73bc9e5ca80 /src/android | |
parent | 54ba9be8850dc7fbeb7151ed5579a22965851008 (diff) |
Android: Fix crashes due to concurrency issues
BroadcastReceiver.onReceive() is executed in the main thread whereas
the Qt classes are in a different thread. This created issues whereby
Java's qtObject pointer was reset by the Qt classes/thread but
onReceive still trying to access the same object later on.
In most cases the Qt classes using BroadcastReceiver were half way
through their object tear down. This patch fixes the problem by
guarding qtObject against concurrent thread access and ensures that
the qtObject pointer is reset before the object tear down starts.
Change-Id: Iab97b0af8e10686d97419ac8504f2fe69e9536f3
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
Diffstat (limited to 'src/android')
-rw-r--r-- | src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver.java | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver.java b/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver.java index 1f0049ef..ba96c0cf 100644 --- a/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver.java +++ b/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver.java @@ -62,7 +62,20 @@ public class QtBluetoothBroadcastReceiver extends BroadcastReceiver public void onReceive(Context context, Intent intent) { - jniOnReceive(qtObject, context, intent); + synchronized (qtactivity) { + if (qtObject == 0) + return; + + jniOnReceive(qtObject, context, intent); + } + } + + public void unregisterReceiver() + { + synchronized (qtactivity) { + qtObject = 0; + qtactivity.unregisterReceiver(this); + } } public native void jniOnReceive(long qtObject, Context context, Intent intent); |