From 38af1f2ab93f2ed20552b0869a02844778138739 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sat, 6 May 2017 11:06:18 -0700 Subject: Check if we have an instance before dereferencing it If we don't have a GPS service userid in the preferences and the GpsLocation class isn't instantiated, this would cause a crash. Fixes #367 Signed-off-by: Dirk Hohndel --- core/gpslocation.cpp | 5 +++++ core/gpslocation.h | 1 + desktop-widgets/subsurfacewebservices.cpp | 3 ++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/core/gpslocation.cpp b/core/gpslocation.cpp index 1c5d378cf..30b101419 100644 --- a/core/gpslocation.cpp +++ b/core/gpslocation.cpp @@ -46,6 +46,11 @@ GpsLocation *GpsLocation::instance() return m_Instance; } +bool GpsLocation::hasInstance() +{ + return m_Instance != NULL; +} + GpsLocation::~GpsLocation() { m_Instance = NULL; diff --git a/core/gpslocation.h b/core/gpslocation.h index 34e0708ff..9922997f1 100644 --- a/core/gpslocation.h +++ b/core/gpslocation.h @@ -27,6 +27,7 @@ public: GpsLocation(void (*showMsgCB)(const char *msg), QObject *parent); ~GpsLocation(); static GpsLocation *instance(); + static bool hasInstance(); bool applyLocations(); int getGpsNum() const; QString getUserid(QString user, QString passwd); diff --git a/desktop-widgets/subsurfacewebservices.cpp b/desktop-widgets/subsurfacewebservices.cpp index 2d8681a8a..1182af097 100644 --- a/desktop-widgets/subsurfacewebservices.cpp +++ b/desktop-widgets/subsurfacewebservices.cpp @@ -398,7 +398,8 @@ SubsurfaceWebServices::SubsurfaceWebServices(QWidget *parent, Qt::WindowFlags f) if (userid.isEmpty() && !same_string(prefs.cloud_storage_email, "") && - !same_string(prefs.cloud_storage_password, "")) + !same_string(prefs.cloud_storage_password, "") && + GpsLocation::hasInstance()) userid = GpsLocation::instance()->getUserid(prefs.cloud_storage_email, prefs.cloud_storage_password); ui.userID->setText(userid); -- cgit v1.2.3-70-g09d2