From a9ceecc2e3646432d6688d04b592c48f9c63ae65 Mon Sep 17 00:00:00 2001 From: "Robert C. Helling" Date: Tue, 29 Aug 2017 11:41:30 +0200 Subject: Run variations calculation in background but there are still side effects and thus it crashes. Signed-off-by: Robert C. Helling --- qt-models/diveplannermodel.cpp | 14 +++++++++++++- qt-models/diveplannermodel.h | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'qt-models') diff --git a/qt-models/diveplannermodel.cpp b/qt-models/diveplannermodel.cpp index 127ea8649..acf2d9c6f 100644 --- a/qt-models/diveplannermodel.cpp +++ b/qt-models/diveplannermodel.cpp @@ -9,6 +9,7 @@ #include "core/subsurface-qt/SettingsObjectWrapper.h" #include #include +#include #define UNIT_FACTOR ((prefs.units.length == units::METERS) ? 1000.0 / 60.0 : feet_to_mm(1.0) / 60.0) @@ -920,7 +921,7 @@ void DivePlannerPointsModel::createTemporaryPlan() if (recalcQ() && !diveplan_empty(&diveplan)) { struct decostop stoptable[60]; plan(&diveplan, &displayed_dive, DECOTIMESTEP, stoptable, &cache, isPlanner(), false); - computeVariations(); + QtConcurrent::run(this, &DivePlannerPointsModel::computeVariations); emit calculatedPlanNotes(); } // throw away the cache @@ -1013,8 +1014,11 @@ void DivePlannerPointsModel::computeVariations() struct divedatapoint *last_segment; if(in_planner() && prefs.display_variations) { + int my_instance = ++instanceCounter; cache_deco_state(&save); cloneDiveplan(&plan_copy); + if (my_instance != instanceCounter) + return; plan(&plan_copy, dive, 1, original, &cache, true, false); free_dps(&plan_copy); restore_deco_state(save, false); @@ -1022,6 +1026,8 @@ void DivePlannerPointsModel::computeVariations() last_segment = cloneDiveplan(&plan_copy); last_segment->depth.mm += 1000; last_segment->next->depth.mm += 1000; + if (my_instance != instanceCounter) + return; plan(&plan_copy, dive, 1, deeper, &cache, true, false); free_dps(&plan_copy); restore_deco_state(save, false); @@ -1029,18 +1035,24 @@ void DivePlannerPointsModel::computeVariations() last_segment = cloneDiveplan(&plan_copy); last_segment->depth.mm -= 1000; last_segment->next->depth.mm -= 1000; + if (my_instance != instanceCounter) + return; plan(&plan_copy, dive, 1, shallower, &cache, true, false); free_dps(&plan_copy); restore_deco_state(save, false); last_segment = cloneDiveplan(&plan_copy); last_segment->next->time += 60; + if (my_instance != instanceCounter) + return; plan(&plan_copy, dive, 1, longer, &cache, true, false); free_dps(&plan_copy); restore_deco_state(save, false); last_segment = cloneDiveplan(&plan_copy); last_segment->next->time -= 60; + if (my_instance != instanceCounter) + return; plan(&plan_copy, dive, 1, shorter, &cache, true, false); free_dps(&plan_copy); restore_deco_state(save, false); diff --git a/qt-models/diveplannermodel.h b/qt-models/diveplannermodel.h index ba9db5e19..a4fe35a65 100644 --- a/qt-models/diveplannermodel.h +++ b/qt-models/diveplannermodel.h @@ -123,6 +123,7 @@ private: QDateTime startTime; int tempGFHigh; int tempGFLow; + int instanceCounter = 0; }; #endif -- cgit v1.2.3-70-g09d2