Crash on shutdown using QGeoAreaMonitorSource on Android
-
Hi,
I'm encountering a crash related to
QGeoAreaMonitorSource
during app shutdown on Android with Qt 5.15.Minimum code to reproduce below. This code works fine on desktop (Linux), but crashes on Android (testing on Android emulator with API 31, but I've seen it on other Android devices). The two cases where it doesn't crash are (1) if you don't call
createDefaultSource()
(i.e. nothing to cleanup), or (2) if the app gets shutdown by the OS (e.g. by swiping up from the app switcher). A normalquit()
call from within the app results in this error. It doesn't seem to matter when or even if I delete my pointer toQGeoAreaMonitorSource
, the crash persists.#include <QGuiApplication> #include <QGeoAreaMonitorSource> #include <QTimer> int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QGeoAreaMonitorSource* pMonitorSrc = QGeoAreaMonitorSource::createDefaultSource( nullptr ); QTimer::singleShot( 1000, [&]() { delete pMonitorSrc; app.quit(); } ); int rc = app.exec(); return rc; }
The crash is a seg-fault with call stack:
1 AndroidPositioning::unregisterPositionInfoSource(int) 0x7e59a7a4f4b7 2 QGeoPositionInfoSourceAndroid::~QGeoPositionInfoSourceAndroid() 0x7e59a7a4e685 3 QGeoPositionInfoSourceAndroid::~QGeoPositionInfoSourceAndroid() 0x7e59a7a4e729 4 QObjectPrivate::deleteChildren() 0x7e59b26a07a5 5 QObject::~QObject() 0x7e59b26a0672 6 (anonymous namespace)::Q_QGS_pollingPrivate::innerFunction()::Holder::~Holder() 0x7e59a471ae16 7 __cxa_finalize 0x7e5ccf85d5d2 8 exit 0x7e5ccf84f2cf 9 startQtApplication(_JNIEnv *, _jclass *) 0x7e59a50f6423 10 ?? 0x7e5a25b9ffac 11 ?? 0x98ad35e000000001 12 ?? 0x7e5b 13 ?? 0x7e5a0abc1cc0 14 ?? 0x2798ad35e0 15 ??
I believe the segfault happens because
idToPosSource()->remove(key)
(inSrc/qtlocation/src/plugins/position/android/src/jnipositioning.cpp
) is accessing a nullptr, presumably due to a shutdown sequencing issue that has madeidToPosSource()
invalid.Is there a way to shutdown cleanly on Android when using
QGeoAreaMonitorSource
, or is this a bug in Qt Positioning?Thanks!
CMG