Skip to content

Commit

Permalink
Use displayed_dc instead of current_dc
Browse files Browse the repository at this point in the history
current_dc is a macro that determines the dive computer
based on the current dive number. When the planner is started
from an emtpy dive list, the dive number ends up being -1 and
that doesn't produce a valid dive computer. Use the divecomputer
of the displayed_dive instead. This is done via a macro that
can also be used in two other places. Without this patch, the
planner crashed when called on an empty dive list.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
  • Loading branch information
atdotde authored and dirkhh committed Oct 19, 2017
1 parent a9b692f commit a422957
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 3 deletions.
1 change: 1 addition & 0 deletions core/dive.h
Expand Up @@ -549,6 +549,7 @@ extern int selected_dive;
extern unsigned int dc_number;
#define current_dive (get_dive(selected_dive))
#define current_dc (get_dive_dc(current_dive, dc_number))
#define displayed_dc (get_dive_dc(&displayed_dive, dc_number))

static inline struct dive *get_dive(int nr)
{
Expand Down
1 change: 1 addition & 0 deletions desktop-widgets/mainwindow.cpp
Expand Up @@ -909,6 +909,7 @@ void MainWindow::setupForAddAndPlan(const char *model)
displayed_dive.id = dive_getUniqID(&displayed_dive);
displayed_dive.when = QDateTime::currentMSecsSinceEpoch() / 1000L + gettimezoneoffset() + 3600;
displayed_dive.dc.model = strdup(model); // don't translate! this is stored in the XML file
dc_number = 1;
// setup the dive cylinders
DivePlannerPointsModel::instance()->clear();
DivePlannerPointsModel::instance()->setupCylinders();
Expand Down
2 changes: 0 additions & 2 deletions desktop-widgets/tab-widgets/maintab.cpp
Expand Up @@ -798,7 +798,6 @@ void MainTab::acceptChanges()
addedId = displayed_dive.id;
}
struct dive *cd = current_dive;
struct divecomputer *displayed_dc = get_dive_dc(&displayed_dive, dc_number);
// now check if something has changed and if yes, edit the selected dives that
// were identical with the master dive shown (and mark the divelist as changed)
if (!same_string(displayed_dive.suit, cd->suit))
Expand Down Expand Up @@ -1145,7 +1144,6 @@ void MainTab::divetype_Changed(int index)
{
if (editMode == IGNORE)
return;
struct divecomputer *displayed_dc = get_dive_dc(&displayed_dive, dc_number);
displayed_dc->divemode = (enum dive_comp_type) index;
update_setpoint_events(&displayed_dive, displayed_dc);
markChangedWidget(ui.DiveType);
Expand Down
2 changes: 1 addition & 1 deletion profile-widget/diveprofileitem.cpp
Expand Up @@ -428,7 +428,7 @@ void DivePercentageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
struct gasmix *gasmix = NULL;
struct event *ev = NULL;
int sec = dataModel->index(i, DivePlotDataModel::TIME).data().toInt();
gasmix = get_gasmix(&displayed_dive, current_dc, sec, &ev, gasmix);
gasmix = get_gasmix(&displayed_dive, displayed_dc, sec, &ev, gasmix);
int inert = 1000 - get_o2(gasmix);
mypen.setBrush(QBrush(ColorScale(value, inert)));
painter->setPen(mypen);
Expand Down

0 comments on commit a422957

Please sign in to comment.