From b9b47092c1ee7b0038c2e5b505925a6da06ac270 Mon Sep 17 00:00:00 2001 From: Michael Keller Date: Sat, 18 Feb 2023 01:45:37 +1300 Subject: [PATCH] Desktop: Fix bug in diveplan for CCR dives with multiple segments. Fixes a bug reported in https://groups.google.com/g/subsurface-divelog/c/8N3cTz2Zv5E: When planning a CCR dive with multiple segments, the textual dive plan was showing a non-existent gas change with bogus data. The first part of the fix is uncluttering of the message printed: Since this change is _after_ the current diveplanpoint the data needs to come from `nextdp` and not `dp`. The second part is that the message is not printed any more if the current and the following segments have been manually added: According to comments in the code the change should only be printed on the segment _before_ the change if this segment is an ascent segment that is followed by a manually entered segment. Signed-off-by: Michael Keller --- CHANGELOG.md | 1 + core/plannernotes.c | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 420c5dd71..e7c9841a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +desktop: fix bug when printing a dive plan with multiple segments desktop: fix bug in bailout gas selection for CCR dives desktop: fix crash on cylinder update of multiple dives desktop: use dynamic tank use drop down in equipment tab and planner diff --git a/core/plannernotes.c b/core/plannernotes.c index 56e0c40cb..bcedaf661 100644 --- a/core/plannernotes.c +++ b/core/plannernotes.c @@ -325,15 +325,15 @@ void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_d /* Normally a gas change is displayed on the stopping segment, so only display a gas change at the end of * an ascent segment if it is not followed by a stop */ - if ((isascent || dp->entered) && gaschange_after && dp->next && nextdp && (dp->depth.mm != nextdp->depth.mm || nextdp->entered)) { - if (dp->setpoint) { - asprintf_loc(&temp, translate("gettextFromC", "(SP = %.1fbar CCR)"), dp->setpoint / 1000.0); + if (isascent && gaschange_after && dp->next && nextdp && nextdp->entered) { + if (nextdp->setpoint) { + asprintf_loc(&temp, translate("gettextFromC", "(SP = %.1fbar CCR)"), nextdp->setpoint / 1000.0); put_format(&buf, "%s %s", gasname(newgasmix), temp); free(temp); } else { put_format(&buf, "%s %s", - gasname(newgasmix), lastdivemode == UNDEF_COMP_TYPE || lastdivemode == dp->divemode ? "" : translate("gettextFromC", divemode_text_ui[dp->divemode])); + gasname(newgasmix), dp->divemode == UNDEF_COMP_TYPE || dp->divemode == nextdp->divemode ? "" : translate("gettextFromC", divemode_text_ui[nextdp->divemode])); if (isascent && (get_he(lastprintgasmix) > 0)) { // For a trimix gas change on ascent, save ICD info if previous cylinder had helium if (isobaric_counterdiffusion(lastprintgasmix, newgasmix, &icdvalues)) // Do icd calulations icdwarning = true; @@ -343,9 +343,9 @@ void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_d } } } - lastprintsetpoint = dp->setpoint; + lastprintsetpoint = nextdp->setpoint; lastprintgasmix = newgasmix; - lastdivemode = dp->divemode; + lastdivemode = nextdp->divemode; gaschange_after = false; } else if (gaschange_before || rebreatherchange_before) { // If a new gas has been used for this segment, now is the time to show it