aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2015-10-30 11:56:56 +0100
committerThomas White <taw@physics.org>2015-10-30 11:59:50 +0100
commit45e5f791a7e9325dbb8f7aef4331d32be17f080c (patch)
tree1938e4701109f425f77e8a4075758ed1021c0254
parentd9ec28efd4c29dbfaa9cc5b2e683f584d720094f (diff)
hdfsee: Fix crash when changing rigid group in calibration mode
The number of rigid groups overall is usually greater than the number of rigid groups in the current collection. Therefore, the "previous rg" function wrapped round to the wrong place.
-rw-r--r--src/dw-hdfsee.c33
1 files changed, 19 insertions, 14 deletions
diff --git a/src/dw-hdfsee.c b/src/dw-hdfsee.c
index f66f37b5..004c92ae 100644
--- a/src/dw-hdfsee.c
+++ b/src/dw-hdfsee.c
@@ -1987,7 +1987,8 @@ static int curr_rg_pointer_index(DisplayWindow *dw)
}
/* Never reached (we hope) */
- return 999;
+ ERROR("Failed to find index for rg!\n");
+ return 0;
}
static int curr_p_pointer_index(DisplayWindow *dw)
@@ -2001,28 +2002,33 @@ static int curr_p_pointer_index(DisplayWindow *dw)
}
/* Never reached (we hope) */
- return 999;
+ ERROR("Failed to find index for panel!\n");
+ return 0;
}
-static void select_next_group(DisplayWindow *dw, int num_rg)
+static void select_next_group(DisplayWindow *dw)
{
- if ( dw->calib_mode_curr_rg == dw->rg_coll->rigid_groups[num_rg-1] ) {
+ int idx = curr_rg_pointer_index(dw);
+ int n_rgs = dw->rg_coll->n_rigid_groups;
+
+ if ( idx == n_rgs-1 ) {
dw->calib_mode_curr_rg = dw->rg_coll->rigid_groups[0];
} else {
- dw->calib_mode_curr_rg =
- dw->rg_coll->rigid_groups[curr_rg_pointer_index(dw)+1];
+ dw->calib_mode_curr_rg = dw->rg_coll->rigid_groups[idx+1];
}
}
-static void select_prev_group(DisplayWindow *dw, int num_rg)
+static void select_prev_group(DisplayWindow *dw)
{
- if ( dw->calib_mode_curr_rg == dw->rg_coll->rigid_groups[0] ) {
- dw->calib_mode_curr_rg = dw->rg_coll->rigid_groups[num_rg-1];
+ int idx = curr_rg_pointer_index(dw);
+ int n_rgs = dw->rg_coll->n_rigid_groups;
+
+ if ( idx == 0 ) {
+ dw->calib_mode_curr_rg = dw->rg_coll->rigid_groups[n_rgs-1];
} else {
- dw->calib_mode_curr_rg =
- dw->rg_coll->rigid_groups[curr_rg_pointer_index(dw)-1];
+ dw->calib_mode_curr_rg = dw->rg_coll->rigid_groups[idx-1];
}
}
@@ -2113,8 +2119,7 @@ static void calibmode_next(GtkWidget *widget, DisplayWindow *dw)
break;
case CALIBMODE_GROUPS:
- n = dw->image->det->n_rigid_groups;
- select_next_group(dw, n);
+ select_next_group(dw);
break;
case CALIBMODE_ALL:
@@ -2141,7 +2146,7 @@ static void calibmode_prev(GtkWidget *widget, DisplayWindow *dw)
case CALIBMODE_GROUPS:
n = dw->image->det->n_rigid_groups;
- select_prev_group(dw, n);
+ select_prev_group(dw);
break;
case CALIBMODE_ALL: