diff options
author | Lincoln Ramsay <lincoln.ramsay@nokia.com> | 2012-05-28 12:20:22 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-05-28 04:58:45 +0200 |
commit | dd14ea8acf97103868d6dfcafb7b19275e605e97 (patch) | |
tree | 74ac18db8f907e2d6e58500c9601cf8dc28ffbfc /src/sensors/gestures | |
parent | 7d54123daa2080f96c7d74f58125141555832b09 (diff) | |
download | qtsensors-dd14ea8acf97103868d6dfcafb7b19275e605e97.tar.gz |
Check for Q_GLOBAL_STATIC returning 0 (Sensor Gestures).
It's probably not very likely but during app shutdown, the
Q_GLOBAL_STATIC used in sensor gestures will start returning 0. Check
for this to avoid the chance of a crash.
Change-Id: I4b538ac9b9535bd9439a897d4eab51211c523e33
Reviewed-by: Lorn Potter <lorn.potter@nokia.com>
Diffstat (limited to 'src/sensors/gestures')
-rw-r--r-- | src/sensors/gestures/qsensorgesturemanager.cpp | 19 | ||||
-rw-r--r-- | src/sensors/gestures/qsensorgesturemanagerprivate.cpp | 5 |
2 files changed, 19 insertions, 5 deletions
diff --git a/src/sensors/gestures/qsensorgesturemanager.cpp b/src/sensors/gestures/qsensorgesturemanager.cpp index 20cdb34..d85051a 100644 --- a/src/sensors/gestures/qsensorgesturemanager.cpp +++ b/src/sensors/gestures/qsensorgesturemanager.cpp @@ -68,7 +68,9 @@ QT_BEGIN_NAMESPACE QSensorGestureManager::QSensorGestureManager(QObject *parent) : QObject(parent) { - connect(QSensorGestureManagerPrivate::instance(),SIGNAL(newSensorGestureAvailable()), + QSensorGestureManagerPrivate *d = QSensorGestureManagerPrivate::instance(); + if (!d) return; // hardly likely but just in case... + connect(d,SIGNAL(newSensorGestureAvailable()), this,SIGNAL(newSensorGestureAvailable())); } @@ -89,7 +91,12 @@ QSensorGestureManager::~QSensorGestureManager() bool QSensorGestureManager::registerSensorGestureRecognizer(QSensorGestureRecognizer *recognizer) { - bool ok = QSensorGestureManagerPrivate::instance()->registerSensorGestureRecognizer(recognizer); + QSensorGestureManagerPrivate *d = QSensorGestureManagerPrivate::instance(); + if (!d) { // hardly likely but just in case... + delete recognizer; + return false; + } + bool ok = d->registerSensorGestureRecognizer(recognizer); if (!ok) delete recognizer; @@ -103,7 +110,9 @@ QSensorGestureManager::~QSensorGestureManager() */ QStringList QSensorGestureManager::gestureIds() const { - return QSensorGestureManagerPrivate::instance()->gestureIds(); + QSensorGestureManagerPrivate *d = QSensorGestureManagerPrivate::instance(); + if (!d) return QStringList(); // hardly likely but just in case... + return d->gestureIds(); } /*! @@ -123,7 +132,9 @@ QSensorGestureManager::~QSensorGestureManager() */ QSensorGestureRecognizer *QSensorGestureManager::sensorGestureRecognizer(const QString &id) { - return QSensorGestureManagerPrivate::instance()->sensorGestureRecognizer(id); + QSensorGestureManagerPrivate *d = QSensorGestureManagerPrivate::instance(); + if (!d) return 0; // hardly likely but just in case... + return d->sensorGestureRecognizer(id); } QT_END_NAMESPACE diff --git a/src/sensors/gestures/qsensorgesturemanagerprivate.cpp b/src/sensors/gestures/qsensorgesturemanagerprivate.cpp index 5e2089a..fc22dc7 100644 --- a/src/sensors/gestures/qsensorgesturemanagerprivate.cpp +++ b/src/sensors/gestures/qsensorgesturemanagerprivate.cpp @@ -236,7 +236,10 @@ void QSensorGestureManagerPrivate::recognizerStopped(const QSensorGestureRecogni QSensorGestureManagerPrivate * QSensorGestureManagerPrivate::instance() { - return sensorGestureManagerPrivate(); + QSensorGestureManagerPrivate *priv = sensorGestureManagerPrivate(); + // It's safe to return 0 because this is checked when used + //if (!priv) qFatal("Cannot return from QSensorGestureManagerPrivate::instance() because sensorGestureManagerPrivate() returned 0."); + return priv; } |