From 887e76497e02b5ffb89bf564872aaa10f0c35cbb Mon Sep 17 00:00:00 2001 From: Lorn Potter Date: Mon, 5 Mar 2012 12:13:21 +1000 Subject: fix crash by initializing orientationReading variable Change-Id: I50fe25627bb761bfb5cb27c882946c13cdbcf56a Reviewed-by: Lincoln Ramsay --- .../qtsensors/qcoversensorgesturerecognizer.cpp | 5 ++++- .../sensorgestures/qtsensors/qslamgesturerecognizer.cpp | 14 ++++++++------ .../qtsensors/qtsensorgesturesensorhandler.cpp | 10 +++++----- .../qtsensors/qtwistsensorgesturerecognizer.cpp | 5 ++++- .../qtsensors/qwhipsensorgesturerecognizer.cpp | 4 +++- 5 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/plugins/sensorgestures/qtsensors/qcoversensorgesturerecognizer.cpp b/src/plugins/sensorgestures/qtsensors/qcoversensorgesturerecognizer.cpp index 47a08f53..5eb06c25 100644 --- a/src/plugins/sensorgestures/qtsensors/qcoversensorgesturerecognizer.cpp +++ b/src/plugins/sensorgestures/qtsensors/qcoversensorgesturerecognizer.cpp @@ -46,7 +46,7 @@ QT_BEGIN_NAMESPACE QCoverSensorGestureRecognizer::QCoverSensorGestureRecognizer(QObject *parent) : QSensorGestureRecognizer(parent), - detecting(0), lastProx(0), proximityReading(0), active(0) + orientationReading(0),lastProx(0), proximityReading(0), active(0), detecting(0) { } @@ -109,6 +109,9 @@ bool QCoverSensorGestureRecognizer::isActive() void QCoverSensorGestureRecognizer::proximityChanged(QIRProximityReading *reading) { + if (orientationReading == 0) + return; + proximityReading = reading->reflectance(); qreal difference = lastProx - proximityReading; diff --git a/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.cpp b/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.cpp index 27ea950e..dd7bcd93 100644 --- a/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.cpp +++ b/src/plugins/sensorgestures/qtsensors/qslamgesturerecognizer.cpp @@ -48,6 +48,7 @@ QT_BEGIN_NAMESPACE QSlamSensorGestureRecognizer::QSlamSensorGestureRecognizer(QObject *parent) : QSensorGestureRecognizer(parent), + orientationReading(0), accelRange(0), active(0), lastX(0), @@ -78,16 +79,15 @@ QString QSlamSensorGestureRecognizer::id() const bool QSlamSensorGestureRecognizer::start() { - connect(QtSensorGestureSensorHandler::instance(),SIGNAL(orientationReadingChanged(QOrientationReading *)), - this,SLOT(orientationReadingChanged(QOrientationReading *))); - - connect(QtSensorGestureSensorHandler::instance(),SIGNAL(accelReadingChanged(QAccelerometerReading *)), - this,SLOT(accelChanged(QAccelerometerReading *))); - if (QtSensorGestureSensorHandler::instance()->startSensor(QtSensorGestureSensorHandler::Accel)) { if (QtSensorGestureSensorHandler::instance()->startSensor(QtSensorGestureSensorHandler::Orientation)) { active = true; accelRange = QtSensorGestureSensorHandler::instance()->accelRange; + connect(QtSensorGestureSensorHandler::instance(),SIGNAL(orientationReadingChanged(QOrientationReading *)), + this,SLOT(orientationReadingChanged(QOrientationReading *))); + + connect(QtSensorGestureSensorHandler::instance(),SIGNAL(accelReadingChanged(QAccelerometerReading *)), + this,SLOT(accelChanged(QAccelerometerReading *))); } else { QtSensorGestureSensorHandler::instance()->stopSensor(QtSensorGestureSensorHandler::Accel); active = false; @@ -132,6 +132,8 @@ void QSlamSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading) qreal z = reading->z(); //// very hacky + if (orientationReading == 0) + return; if (orientationReading->orientation() == QOrientationReading::FaceUp) { z = z - 9.8; } diff --git a/src/plugins/sensorgestures/qtsensors/qtsensorgesturesensorhandler.cpp b/src/plugins/sensorgestures/qtsensors/qtsensorgesturesensorhandler.cpp index 676e94f9..028ab041 100644 --- a/src/plugins/sensorgestures/qtsensors/qtsensorgesturesensorhandler.cpp +++ b/src/plugins/sensorgestures/qtsensors/qtsensorgesturesensorhandler.cpp @@ -89,7 +89,7 @@ bool QtSensorGestureSensorHandler::startSensor(SensorGestureSensors sensor) switch (sensor) { case Accel: //accel - if (!accel) { + if (accel == 0x0) { accel = new QAccelerometer(this); ok = accel->connectToBackend(); qoutputrangelist outputranges = accel->outputRanges(); @@ -105,7 +105,7 @@ bool QtSensorGestureSensorHandler::startSensor(SensorGestureSensors sensor) break; case Orientation: //orientation - if (!orientation) { + if (orientation == 0x0) { orientation = new QOrientationSensor(this); ok = orientation->connectToBackend(); connect(orientation,SIGNAL(readingChanged()),this,SLOT(orientationChanged())); @@ -115,7 +115,7 @@ bool QtSensorGestureSensorHandler::startSensor(SensorGestureSensors sensor) break; case Proximity: //proximity - if (!proximity) { + if (proximity == 0x0) { proximity = new QProximitySensor(this); ok = proximity->connectToBackend(); connect(proximity,SIGNAL(readingChanged()),this,SLOT(proximityChanged())); @@ -125,7 +125,7 @@ bool QtSensorGestureSensorHandler::startSensor(SensorGestureSensors sensor) break; case IrProximity: //irproximity - if (!irProx) { + if (irProx == 0x0) { irProx = new QIRProximitySensor(this); ok = irProx->connectToBackend(); connect(irProx,SIGNAL(readingChanged()),this,SLOT(irProximityChanged())); @@ -135,7 +135,7 @@ bool QtSensorGestureSensorHandler::startSensor(SensorGestureSensors sensor) break; case Tap: //dtap - if (!tapSensor) { + if (tapSensor == 0x0) { tapSensor = new QTapSensor(this); ok = tapSensor->connectToBackend(); connect(tapSensor,SIGNAL(readingChanged()),this,SLOT(doubletap())); diff --git a/src/plugins/sensorgestures/qtsensors/qtwistsensorgesturerecognizer.cpp b/src/plugins/sensorgestures/qtsensors/qtwistsensorgesturerecognizer.cpp index 3db09ba2..1a3106d7 100644 --- a/src/plugins/sensorgestures/qtsensors/qtwistsensorgesturerecognizer.cpp +++ b/src/plugins/sensorgestures/qtsensors/qtwistsensorgesturerecognizer.cpp @@ -50,7 +50,7 @@ QT_BEGIN_NAMESPACE QTwistSensorGestureRecognizer::QTwistSensorGestureRecognizer(QObject *parent) : QSensorGestureRecognizer(parent), - accelRange(0), lastRoll(0), active(0), pitch(0), detecting(0), lastDegree(0), + accelRange(0), orientationReading(0), lastRoll(0), active(0), pitch(0), detecting(0), lastDegree(0), lastX(0), lastY(0), lastZ() { } @@ -131,6 +131,9 @@ void QTwistSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading) qreal degrees = qAtan(x / qSqrt(y*y + z*z)) * RADIANS_TO_DEGREES; + if (orientationReading == 0) + return; + if (rollList.count() > 4) { if (detecting && isShake()) { diff --git a/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.cpp b/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.cpp index 8d4eb1a5..a8b90925 100644 --- a/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.cpp +++ b/src/plugins/sensorgestures/qtsensors/qwhipsensorgesturerecognizer.cpp @@ -48,7 +48,7 @@ QT_BEGIN_NAMESPACE QWhipSensorGestureRecognizer::QWhipSensorGestureRecognizer(QObject *parent) : - QSensorGestureRecognizer(parent), whipIt(0), lastX(0), + QSensorGestureRecognizer(parent), orientationReading(0), whipIt(0), lastX(0), detectedX(0), active(0) { } @@ -132,6 +132,8 @@ void QWhipSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading) if (qAbs(difference) < 1) return; + if (orientationReading == 0) + return; qreal y = reading->y(); qreal z = reading->z(); -- cgit v1.2.3