Unverified Commit 45d8d890 authored by Don Gagne's avatar Don Gagne Committed by GitHub

Merge pull request #6104 from DonLakeFlyer/TerrainCrash

Terrain crash
parents 03465774 ce4a0e67
...@@ -479,6 +479,7 @@ void MissionController::removeAll(void) ...@@ -479,6 +479,7 @@ void MissionController::removeAll(void)
{ {
if (_visualItems) { if (_visualItems) {
_deinitAllVisualItems(); _deinitAllVisualItems();
_visualItems->clearAndDeleteContents();
_visualItems->deleteLater(); _visualItems->deleteLater();
_settingsItem = NULL; _settingsItem = NULL;
_visualItems = new QmlObjectListModel(this); _visualItems = new QmlObjectListModel(this);
......
...@@ -33,6 +33,8 @@ TerrainBatchManager::TerrainBatchManager(void) ...@@ -33,6 +33,8 @@ TerrainBatchManager::TerrainBatchManager(void)
void TerrainBatchManager::addQuery(ElevationProvider* elevationProvider, const QList<QGeoCoordinate>& coordinates) void TerrainBatchManager::addQuery(ElevationProvider* elevationProvider, const QList<QGeoCoordinate>& coordinates)
{ {
if (coordinates.length() > 0) { if (coordinates.length() > 0) {
qCDebug(ElevationProviderLog) << "addQuery: elevationProvider:coordinates.count" << elevationProvider << coordinates.count();
connect(elevationProvider, &ElevationProvider::destroyed, this, &TerrainBatchManager::_elevationProviderDestroyed);
QueuedRequestInfo_t queuedRequestInfo = { elevationProvider, coordinates }; QueuedRequestInfo_t queuedRequestInfo = { elevationProvider, coordinates };
_requestQueue.append(queuedRequestInfo); _requestQueue.append(queuedRequestInfo);
if (!_batchTimer.isActive()) { if (!_batchTimer.isActive()) {
...@@ -43,7 +45,7 @@ void TerrainBatchManager::addQuery(ElevationProvider* elevationProvider, const Q ...@@ -43,7 +45,7 @@ void TerrainBatchManager::addQuery(ElevationProvider* elevationProvider, const Q
void TerrainBatchManager::_sendNextBatch(void) void TerrainBatchManager::_sendNextBatch(void)
{ {
qCDebug(ElevationProviderLog) << "_sendNextBatch _state:_requestQueue.count" << (int)_state << _requestQueue.count(); qCDebug(ElevationProviderLog) << "_sendNextBatch _state:_requestQueue.count:_sentRequests.count" << _stateToString(_state) << _requestQueue.count() << _sentRequests.count();
if (_state != State::Idle) { if (_state != State::Idle) {
// Waiting for last download the complete, wait some more // Waiting for last download the complete, wait some more
...@@ -60,7 +62,7 @@ void TerrainBatchManager::_sendNextBatch(void) ...@@ -60,7 +62,7 @@ void TerrainBatchManager::_sendNextBatch(void)
// Convert coordinates to point strings for json query // Convert coordinates to point strings for json query
QString points; QString points;
foreach (const QueuedRequestInfo_t& requestInfo, _requestQueue) { foreach (const QueuedRequestInfo_t& requestInfo, _requestQueue) {
SentRequestInfo_t sentRequestInfo = { requestInfo.elevationProvider, requestInfo.coordinates.count() }; SentRequestInfo_t sentRequestInfo = { requestInfo.elevationProvider, false, requestInfo.coordinates.count() };
qCDebug(ElevationProviderLog) << "Building request: coordinate count" << requestInfo.coordinates.count(); qCDebug(ElevationProviderLog) << "Building request: coordinate count" << requestInfo.coordinates.count();
_sentRequests.append(sentRequestInfo); _sentRequests.append(sentRequestInfo);
...@@ -100,8 +102,11 @@ void TerrainBatchManager::_batchFailed(void) ...@@ -100,8 +102,11 @@ void TerrainBatchManager::_batchFailed(void)
QList<float> noAltitudes; QList<float> noAltitudes;
foreach (const SentRequestInfo_t& sentRequestInfo, _sentRequests) { foreach (const SentRequestInfo_t& sentRequestInfo, _sentRequests) {
if (!sentRequestInfo.providerDestroyed) {
disconnect(sentRequestInfo.elevationProvider, &ElevationProvider::destroyed, this, &TerrainBatchManager::_elevationProviderDestroyed);
sentRequestInfo.elevationProvider->_signalTerrainData(false, noAltitudes); sentRequestInfo.elevationProvider->_signalTerrainData(false, noAltitudes);
} }
}
_sentRequests.clear(); _sentRequests.clear();
} }
...@@ -145,15 +150,56 @@ void TerrainBatchManager::_requestFinished() ...@@ -145,15 +150,56 @@ void TerrainBatchManager::_requestFinished()
int currentIndex = 0; int currentIndex = 0;
foreach (const SentRequestInfo_t& sentRequestInfo, _sentRequests) { foreach (const SentRequestInfo_t& sentRequestInfo, _sentRequests) {
if (!sentRequestInfo.providerDestroyed) {
disconnect(sentRequestInfo.elevationProvider, &ElevationProvider::destroyed, this, &TerrainBatchManager::_elevationProviderDestroyed);
QList<float> requestAltitudes = altitudes.mid(currentIndex, sentRequestInfo.cCoord); QList<float> requestAltitudes = altitudes.mid(currentIndex, sentRequestInfo.cCoord);
sentRequestInfo.elevationProvider->_signalTerrainData(true, requestAltitudes); sentRequestInfo.elevationProvider->_signalTerrainData(true, requestAltitudes);
currentIndex += sentRequestInfo.cCoord; currentIndex += sentRequestInfo.cCoord;
} }
}
_sentRequests.clear(); _sentRequests.clear();
reply->deleteLater(); reply->deleteLater();
} }
void TerrainBatchManager::_elevationProviderDestroyed(QObject* elevationProvider)
{
// Remove/Mark deleted objects queries from queues
qCDebug(ElevationProviderLog) << "_elevationProviderDestroyed elevationProvider" << elevationProvider;
int i = 0;
while (i < _requestQueue.count()) {
const QueuedRequestInfo_t& requestInfo = _requestQueue[i];
if (requestInfo.elevationProvider == elevationProvider) {
qCDebug(ElevationProviderLog) << "Removing deleted provider from _requestQueue index:elevationProvider" << i << requestInfo.elevationProvider;
_requestQueue.removeAt(i);
} else {
i++;
}
}
for (int i=0; i<_sentRequests.count(); i++) {
SentRequestInfo_t& sentRequestInfo = _sentRequests[i];
if (sentRequestInfo.elevationProvider == elevationProvider) {
qCDebug(ElevationProviderLog) << "Zombieing deleted provider from _sentRequests index:elevatationProvider" << sentRequestInfo.elevationProvider;
sentRequestInfo.providerDestroyed = true;
}
}
}
QString TerrainBatchManager::_stateToString(State state)
{
switch (state) {
case State::Idle:
return QStringLiteral("Idle");
case State::Downloading:
return QStringLiteral("Downloading");
}
return QStringLiteral("State unknown");
}
ElevationProvider::ElevationProvider(QObject* parent) ElevationProvider::ElevationProvider(QObject* parent)
: QObject(parent) : QObject(parent)
{ {
...@@ -161,7 +207,6 @@ ElevationProvider::ElevationProvider(QObject* parent) ...@@ -161,7 +207,6 @@ ElevationProvider::ElevationProvider(QObject* parent)
} }
void ElevationProvider::queryTerrainData(const QList<QGeoCoordinate>& coordinates) void ElevationProvider::queryTerrainData(const QList<QGeoCoordinate>& coordinates)
{ {
qCDebug(ElevationProviderLog) << "queryTerrainData: coordinate count" << coordinates.count();
if (coordinates.length() == 0) { if (coordinates.length() == 0) {
return; return;
} }
......
...@@ -32,6 +32,7 @@ public: ...@@ -32,6 +32,7 @@ public:
private slots: private slots:
void _sendNextBatch (void); void _sendNextBatch (void);
void _requestFinished (void); void _requestFinished (void);
void _elevationProviderDestroyed (QObject* elevationProvider);
private: private:
typedef struct { typedef struct {
...@@ -41,6 +42,7 @@ private: ...@@ -41,6 +42,7 @@ private:
typedef struct { typedef struct {
ElevationProvider* elevationProvider; ElevationProvider* elevationProvider;
bool providerDestroyed;
int cCoord; int cCoord;
} SentRequestInfo_t; } SentRequestInfo_t;
...@@ -51,6 +53,7 @@ private: ...@@ -51,6 +53,7 @@ private:
}; };
void _batchFailed(void); void _batchFailed(void);
QString _stateToString(State state);
QList<QueuedRequestInfo_t> _requestQueue; QList<QueuedRequestInfo_t> _requestQueue;
QList<SentRequestInfo_t> _sentRequests; QList<SentRequestInfo_t> _sentRequests;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment