From c63594acecf11b2201d4f356701be74b57eb9dff Mon Sep 17 00:00:00 2001 From: James Turner Date: Mon, 2 Nov 2020 14:55:35 +0000 Subject: [PATCH] =?UTF-8?q?Launcher:=20abandon=20NautralEarth=20loading=20?= =?UTF-8?q?on=20=E2=80=98fly!=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Otherwise we waste time trying to commit loaded data during FG main startup, which causes races on the NavCache, and is pointless. --- src/GUI/QtLauncher.cxx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/GUI/QtLauncher.cxx b/src/GUI/QtLauncher.cxx index 7d07d242f..b531fc8dd 100644 --- a/src/GUI/QtLauncher.cxx +++ b/src/GUI/QtLauncher.cxx @@ -39,6 +39,7 @@ #include #include #include +#include // Simgear #include @@ -187,6 +188,10 @@ public: connect(this, &QThread::finished, this, &NaturalEarthDataLoaderThread::onFinished); } + void abandon() + { + m_abandoned = true; + } protected: void run() override { @@ -199,6 +204,9 @@ protected: private: Q_SLOT void onFinished() { + if (m_abandoned) + return; + flightgear::PolyLineList::const_iterator begin = m_parsedLines.begin() + m_lineInsertCount; unsigned int numToAdd = std::min(1000U, static_cast(m_parsedLines.size()) - m_lineInsertCount); flightgear::PolyLineList::const_iterator end = begin + numToAdd; @@ -228,6 +236,7 @@ private: flightgear::PolyLineList m_parsedLines; unsigned int m_lineInsertCount; + bool m_abandoned = false; }; } // of anonymous namespace @@ -511,7 +520,7 @@ bool runLauncherDialog() // will happen as normal http->init(); - NaturalEarthDataLoaderThread* naturalEarthLoader = new NaturalEarthDataLoaderThread; + QPointer naturalEarthLoader = new NaturalEarthDataLoaderThread; naturalEarthLoader->start(); // avoid double Apple menu and other weirdness if both Qt and OSG @@ -530,6 +539,12 @@ bool runLauncherDialog() return false; // quit } + // avoid crashes / NavCache races if the loader is still running after + // the launcher exits + if (naturalEarthLoader) { + naturalEarthLoader->abandon(); + } + // avoid a race-y crash on the locale, if a scan thread is // still running: this reset will cancel any running scan LocalAircraftCache::reset();