summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/dive.c5
-rw-r--r--core/equipment.c5
-rw-r--r--core/planner.c18
3 files changed, 19 insertions, 9 deletions
diff --git a/core/dive.c b/core/dive.c
index 89e090165..b4fa22d24 100644
--- a/core/dive.c
+++ b/core/dive.c
@@ -227,7 +227,10 @@ struct event *add_event(struct divecomputer *dc, unsigned int time, int type, in
void add_gas_switch_event(struct dive *dive, struct divecomputer *dc, int seconds, int idx)
{
/* sanity check so we don't crash */
- if (idx < 0 || idx >= dive->cylinders.nr) {
+ /* FIXME: The planner uses a dummy cylinder one past the official number of cylinders
+ * in the table to mark no-cylinder surface interavals. This is horrendous. Fix ASAP. */
+ //if (idx < 0 || idx >= dive->cylinders.nr) {
+ if (idx < 0 || idx >= dive->cylinders.nr + 1 || idx >= dive->cylinders.allocated) {
report_error("Unknown cylinder index: %d", idx);
return;
}
diff --git a/core/equipment.c b/core/equipment.c
index 8d169d8d2..a5acb776d 100644
--- a/core/equipment.c
+++ b/core/equipment.c
@@ -368,7 +368,10 @@ cylinder_t *add_empty_cylinder(struct cylinder_table *t)
*/
cylinder_t *get_cylinder(const struct dive *d, int idx)
{
- if (idx < 0 || idx >= d->cylinders.nr) {
+ /* FIXME: The planner uses a dummy cylinder one past the official number of cylinders
+ * in the table to mark no-cylinder surface interavals. This is horrendous. Fix ASAP. */
+ // if (idx < 0 || idx >= d->cylinders.nr) {
+ if (idx < 0 || idx >= d->cylinders.nr + 1 || idx >= d->cylinders.allocated) {
fprintf(stderr, "Warning: accessing invalid cylinder %d (%d existing)\n", idx, d->cylinders.nr);
return NULL;
}
diff --git a/core/planner.c b/core/planner.c
index 8cadaca01..f4fb9ee80 100644
--- a/core/planner.c
+++ b/core/planner.c
@@ -272,7 +272,11 @@ static void create_dive_from_plan(struct diveplan *diveplan, struct dive *dive,
if (dp->cylinderid != lastcylid) {
/* need to insert a first sample for the new gas */
add_gas_switch_event(dive, dc, lasttime + 1, dp->cylinderid);
- cyl = get_or_create_cylinder(dive, dp->cylinderid);
+ cyl = get_cylinder(dive, dp->cylinderid); // FIXME: This actually may get one past the last cylinder for "surface air".
+ if (!cyl) {
+ report_error("Invalid cylinder in create_dive_from_plan(): %d", dp->cylinderid);
+ continue;
+ }
sample = prepare_sample(dc);
sample[-1].setpoint.mbar = po2;
sample->time.seconds = lasttime + 1;
@@ -1070,12 +1074,12 @@ bool plan(struct deco_state *ds, struct diveplan *diveplan, struct dive *dive, i
}
if (prefs.surface_segment != 0) {
- // Switch to an empty air cylinder for breathing air at the surface
- // If no empty cylinder is found, keep using last deco gas
- cylinder_t cyl = empty_cylinder;
- cyl.cylinder_use = NOT_USED;
- add_cylinder(&dive->cylinders, dive->cylinders.nr, cyl);
- current_cylinder = dive->cylinders.nr - 1;
+ // Switch to an empty air cylinder for breathing air at the surface.
+ // FIXME: This is incredibly silly and emulates the old code when
+ // we had a fixed cylinder table: It uses an extra fake cylinder
+ // past the regular cylinder table, which is not visible to the UI.
+ // Fix this as soon as possible!
+ current_cylinder = dive->cylinders.nr;
plan_add_segment(diveplan, prefs.surface_segment, 0, current_cylinder, 0, false, OC);
}
create_dive_from_plan(diveplan, dive, is_planner);