On 24/02/15 16:54, Tomasz Buchert wrote:
> Control: tag -1 confirmed
> 
> Ok, I didn't understand your first instructions.
> It is reproducible by me as well. I'll take a look at it
> later today.
> 

I found the problem - Location dialog launches Network Request
asynchronously on every click of the checkbox. However each request
uses the same global variable which creates a race condition. Our
problem happens, because QNetworkReply that was already deleted is
used by another async. request.
I attach a patch that fixes this for me and I'm contacting stellarium
devs to tell them about it.

Thanks Adam,
Tomasz
From: Tomasz Buchert <tomasz.buch...@inria.fr>
Date: Tue, 24 Feb 2015 22:33:20 +0100
Subject: test

---
 src/core/StelLocationMgr.cpp | 4 ++--
 src/core/StelLocationMgr.hpp | 4 ----
 2 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/src/core/StelLocationMgr.cpp b/src/core/StelLocationMgr.cpp
index f922a95..dd37c57 100644
--- a/src/core/StelLocationMgr.cpp
+++ b/src/core/StelLocationMgr.cpp
@@ -35,7 +35,6 @@
 #include <QSettings>
 
 StelLocationMgr::StelLocationMgr()
-	: networkReply(NULL)
 {
 	QSettings* conf = StelApp::getInstance().getSettings();
 
@@ -345,7 +344,7 @@ bool StelLocationMgr::deleteUserLocation(const QString& id)
 void StelLocationMgr::locationFromIP()
 {
 	QNetworkRequest req( QUrl( QString("http://freegeoip.net/csv/";) ) );
-	networkReply=StelApp::getInstance().getNetworkAccessManager()->get(req);
+	QNetworkReply* networkReply=StelApp::getInstance().getNetworkAccessManager()->get(req);
 	connect(networkReply, SIGNAL(finished()), this, SLOT(changeLocationFromNetworkLookup()));
 }
 
@@ -354,6 +353,7 @@ void StelLocationMgr::changeLocationFromNetworkLookup()
 {
 	StelLocation location;
 	StelCore *core=StelApp::getInstance().getCore();
+	QNetworkReply* networkReply = static_cast<QNetworkReply*>(sender());
 	if (networkReply->error() == QNetworkReply::NoError) {
 		//success
 		// Tested with and without working network connection.
diff --git a/src/core/StelLocationMgr.hpp b/src/core/StelLocationMgr.hpp
index 36d9eee..31ff428 100644
--- a/src/core/StelLocationMgr.hpp
+++ b/src/core/StelLocationMgr.hpp
@@ -108,10 +108,6 @@ private:
 	QMap<QString, StelLocation> pickedLocations;
 	
 	StelLocation lastResortLocation;
-
-	//! For IP-based location lookup
-	QNetworkReply *networkReply;
-
 };
 
 #endif // _STELLOCATIONMGR_HPP_

Reply via email to