From e921715410b6ea363172170f5750f1db1bbc5441 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Tue, 6 Aug 2019 11:35:56 +0200 Subject: Planner: pass dive to enough_gas() Enough gas was checking the currently displayed dive instead of the dive to be planned. Not good in a multi-threaded context. Pass the actual dive instead. Signed-off-by: Berthold Stoeger --- core/planner.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/core/planner.c b/core/planner.c index fd6c13604..2ce001d39 100644 --- a/core/planner.c +++ b/core/planner.c @@ -595,10 +595,9 @@ static bool trial_ascent(struct deco_state *ds, int wait_time, int trial_depth, * Also return true if this cannot be calculated because the cylinder doesn't have * size or a starting pressure. */ -static bool enough_gas(int current_cylinder) +static bool enough_gas(const struct dive *dive, int current_cylinder) { - cylinder_t *cyl; - cyl = &displayed_dive.cylinder[current_cylinder]; + const cylinder_t *cyl = &dive->cylinder[current_cylinder]; if (!cyl->start.mbar) return true; @@ -793,7 +792,7 @@ bool plan(struct deco_state *ds, struct diveplan *diveplan, struct dive *dive, i clock += timestep; } while (trial_ascent(ds, 0, depth, 0, avg_depth, bottom_time, dive->cylinder[current_cylinder].gasmix, po2, diveplan->surface_pressure / 1000.0, dive, divemode) && - enough_gas(current_cylinder) && clock < 6 * 3600); + enough_gas(dive, current_cylinder) && clock < 6 * 3600); // We did stay one DECOTIMESTEP too many. // In the best of all worlds, we would roll back also the last add_segment in terms of caching deco state, but -- cgit v1.2.3-70-g09d2