Skip to content

Commit 7e5c9b5

Browse files
Safe pipeline gui functions (shutdown part 3)
If we process the pixelpipe after dt_control_quit() the gui is not available any more and thus also the references to it in the pipe's dev. The relevant functions are 1. the checking for module being in focus, instead of adding an additional check all over the code dt_iop_has_focus() has been introduced and used all over the code where correct. 2. dt_dev_gui_module(void) also tests for a gui being available
1 parent 2134308 commit 7e5c9b5

10 files changed

+38
-58
lines changed

src/develop/blend.c

+4-14
Original file line numberDiff line numberDiff line change
@@ -504,9 +504,7 @@ void dt_develop_blend_process(dt_iop_module_t *self,
504504
const dt_iop_roi_t *const roi_in,
505505
const dt_iop_roi_t *const roi_out)
506506
{
507-
if(piece->pipe->bypass_blendif
508-
&& self->dev->gui_attached
509-
&& (self == self->dev->gui_module))
507+
if(piece->pipe->bypass_blendif && dt_iop_has_focus(self))
510508
return;
511509

512510
const dt_develop_blend_params_t *const d = piece->blendop_data;
@@ -545,10 +543,7 @@ void dt_develop_blend_process(dt_iop_module_t *self,
545543
return;
546544
}
547545

548-
const gboolean valid_request =
549-
self->dev->gui_attached
550-
&& (self == self->dev->gui_module)
551-
&& (piece->pipe == self->dev->full.pipe);
546+
const gboolean valid_request = dt_iop_has_focus(self) && (piece->pipe == self->dev->full.pipe);
552547

553548
// does user want us to display a specific channel?
554549
const dt_dev_pixelpipe_display_mask_t request_mask_display =
@@ -934,9 +929,7 @@ gboolean dt_develop_blend_process_cl(dt_iop_module_t *self,
934929
const dt_iop_roi_t *roi_in,
935930
const dt_iop_roi_t *roi_out)
936931
{
937-
if(piece->pipe->bypass_blendif
938-
&& self->dev->gui_attached
939-
&& (self == self->dev->gui_module))
932+
if(piece->pipe->bypass_blendif && dt_iop_has_focus(self))
940933
return TRUE;
941934

942935
dt_develop_blend_params_t *const d = piece->blendop_data;
@@ -971,10 +964,7 @@ gboolean dt_develop_blend_process_cl(dt_iop_module_t *self,
971964
// only non-zero if mask_display was set by an _earlier_ module
972965
const dt_dev_pixelpipe_display_mask_t mask_display = piece->pipe->mask_display;
973966

974-
const gboolean valid_request =
975-
self->dev->gui_attached
976-
&& (self == self->dev->gui_module)
977-
&& (piece->pipe == self->dev->full.pipe);
967+
const gboolean valid_request = dt_iop_has_focus(self) && (piece->pipe == self->dev->full.pipe);
978968

979969
// does user want us to display a specific channel?
980970
const dt_dev_pixelpipe_display_mask_t request_mask_display =

src/develop/develop.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ void dt_dev_init_chroma(dt_develop_t *dev);
616616
void dt_dev_clear_chroma_troubles(dt_develop_t *dev);
617617
static inline struct dt_iop_module_t *dt_dev_gui_module(void)
618618
{
619-
return darktable.develop ? darktable.develop->gui_module : NULL;
619+
return (darktable.develop && darktable.gui) ? darktable.develop->gui_module : NULL;
620620
}
621621

622622
#ifdef __cplusplus

src/develop/imageop.c

+13-1
Original file line numberDiff line numberDiff line change
@@ -2310,6 +2310,17 @@ static gboolean _presets_scroll_callback(GtkWidget *widget,
23102310
return TRUE;
23112311
}
23122312

2313+
// Make sure we don't dereference if not in UI mode any more
2314+
gboolean dt_iop_has_focus(dt_iop_module_t *module)
2315+
{
2316+
return module
2317+
&& module->dev
2318+
&& module->dev->gui_attached
2319+
&& module == module->dev->gui_module
2320+
&& darktable.gui
2321+
&& dt_dev_modulegroups_test_activated(darktable.develop);
2322+
}
2323+
23132324
void dt_iop_request_focus(dt_iop_module_t *module)
23142325
{
23152326
dt_develop_t *dev = darktable.develop;
@@ -2320,7 +2331,8 @@ void dt_iop_request_focus(dt_iop_module_t *module)
23202331
if(!darktable.lib->proxy.colorpicker.restrict_histogram)
23212332
dt_iop_color_picker_reset(NULL, TRUE);
23222333

2323-
if(darktable.gui->reset
2334+
if(!darktable.gui
2335+
|| darktable.gui->reset
23242336
|| (out_focus_module == module))
23252337
return;
23262338

src/develop/imageop.h

+2
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,8 @@ GtkWidget *dt_iop_gui_header_button(dt_iop_module_t *module,
412412

413413
/** requests the focus for this plugin (to draw overlays over the center image) */
414414
void dt_iop_request_focus(dt_iop_module_t *module);
415+
/** returns TRUE if tested module has focus */
416+
gboolean dt_iop_has_focus(dt_iop_module_t *module);
415417
/** allocate and load default settings from introspection. */
416418
void dt_iop_default_init(dt_iop_module_t *module);
417419
/** loads default settings from database. */

src/iop/ashift.c

+3-10
Original file line numberDiff line numberDiff line change
@@ -4054,13 +4054,6 @@ static gboolean _get_points(dt_iop_module_t *self,
40544054
return FALSE;
40554055
}
40564056

4057-
// does this gui have focus?
4058-
static gboolean _gui_has_focus(dt_iop_module_t *self)
4059-
{
4060-
return (self->dev->gui_module == self
4061-
&& dt_dev_modulegroups_test_activated(darktable.develop));
4062-
}
4063-
40644057
/* this function replaces this sentence, it calls distort_transform()
40654058
for this module on the pipe
40664059
if(!dt_dev_distort_transform_plus(self->dev, self->dev->preview_pipe,
@@ -4154,7 +4147,7 @@ void gui_post_expose(dt_iop_module_t *self,
41544147

41554148
// we draw the cropping area; we need x_off/y_off/width/height which is only available
41564149
// after g->buf has been processed
4157-
if(g->buf && self->enabled && _gui_has_focus(self))
4150+
if(g->buf && self->enabled && dt_iop_has_focus(self))
41584151
{
41594152
// roi data of the preview pipe input buffer
41604153

@@ -4354,7 +4347,7 @@ void gui_post_expose(dt_iop_module_t *self,
43544347
if(g->fitting) return;
43554348

43564349
// no structural data or visibility switched off? -> stop here
4357-
if(g->lines == NULL || !_gui_has_focus(self)) return;
4350+
if(g->lines == NULL || !dt_iop_has_focus(self)) return;
43584351

43594352
// get hash value that reflects distortions from here to the end of the pixelpipe
43604353
const dt_hash_t hash = dt_dev_hash_distort_plus(dev,
@@ -5630,7 +5623,7 @@ void commit_params(dt_iop_module_t *self,
56305623
d->orthocorr = (p->mode == ASHIFT_MODE_GENERIC) ? 0.0f : p->orthocorr;
56315624
d->aspect = (p->mode == ASHIFT_MODE_GENERIC) ? 1.0f : p->aspect;
56325625

5633-
if(_gui_has_focus(self)
5626+
if(dt_iop_has_focus(self)
56345627
|| dt_isnan(p->cl)
56355628
|| dt_isnan(p->cr)
56365629
|| dt_isnan(p->ct)

src/iop/clipping.c

+1-7
Original file line numberDiff line numberDiff line change
@@ -391,12 +391,6 @@ dt_iop_colorspace_type_t default_colorspace(dt_iop_module_t *self,
391391
return IOP_CS_RGB;
392392
}
393393

394-
static int gui_has_focus(dt_iop_module_t *self)
395-
{
396-
return (self->dev->gui_module == self
397-
&& dt_dev_modulegroups_test_activated(darktable.develop));
398-
}
399-
400394
static void keystone_get_matrix(const dt_boundingbox_t k_space, float kxa, float kxb, float kxc, float kxd, float kya,
401395
float kyb, float kyc, float kyd, float *a, float *b, float *d, float *e,
402396
float *g, float *h)
@@ -1328,7 +1322,7 @@ void commit_params(dt_iop_module_t *self, dt_iop_params_t *p1, dt_dev_pixelpipe_
13281322
d->k_apply = 0;
13291323
}
13301324

1331-
if(gui_has_focus(self))
1325+
if(dt_iop_has_focus(self))
13321326
{
13331327
d->cx = 0.0f;
13341328
d->cy = 0.0f;

src/iop/colorequal.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2537,7 +2537,7 @@ static gboolean _iop_colorequalizer_draw(GtkWidget *widget,
25372537

25382538
dt_free_align(g->LUT);
25392539

2540-
if(self->enabled && (self == self->dev->gui_module) && g->picking)
2540+
if(self->enabled && dt_iop_has_focus(self) && g->picking)
25412541
_draw_color_picker(self, cr, p, g, (double)graph_width, (double)graph_height);
25422542

25432543
cairo_restore(cr);

src/iop/colorzones.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,9 @@ void process(dt_iop_module_t *self,
585585
// display selection if requested
586586
if((piece->pipe->type & DT_DEV_PIXELPIPE_FULL)
587587
&& g
588-
&& g->display_mask && self->dev->gui_attached
589-
&& (self == self->dev->gui_module) && (piece->pipe == self->dev->full.pipe))
588+
&& g->display_mask
589+
&& dt_iop_has_focus(self)
590+
&& (piece->pipe == self->dev->full.pipe))
590591
process_display(self, piece, ivoid, ovoid, roi_in, roi_out);
591592
else if(d->mode == DT_IOP_COLORZONES_MODE_SMOOTH)
592593
process_v3(self, piece, ivoid, ovoid, roi_in, roi_out);

src/iop/crop.c

+1-7
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,6 @@ dt_iop_colorspace_type_t default_colorspace(dt_iop_module_t *self,
166166
return IOP_CS_RGB;
167167
}
168168

169-
static int _gui_has_focus(dt_iop_module_t *self)
170-
{
171-
return (self->dev->gui_module == self
172-
&& dt_dev_modulegroups_test_activated(darktable.develop));
173-
}
174-
175169
static void _commit_box(dt_iop_module_t *self,
176170
dt_iop_crop_gui_data_t *g,
177171
dt_iop_crop_params_t *p)
@@ -421,7 +415,7 @@ void commit_params(dt_iop_module_t *self,
421415
dt_iop_crop_params_t *p = (dt_iop_crop_params_t *)p1;
422416
dt_iop_crop_data_t *d = piece->data;
423417

424-
if(_gui_has_focus(self) && (pipe->type & DT_DEV_PIXELPIPE_BASIC))
418+
if(dt_iop_has_focus(self) && (pipe->type & DT_DEV_PIXELPIPE_BASIC))
425419
{
426420
d->cx = 0.0f;
427421
d->cy = 0.0f;

src/iop/retouch.c

+9-15
Original file line numberDiff line numberDiff line change
@@ -3860,9 +3860,7 @@ void process(dt_iop_module_t *self,
38603860
retouch_user_data_t usr_data = { 0 };
38613861
dwt_params_t *dwt_p = NULL;
38623862

3863-
const int gui_active = (self->dev) ? (self == self->dev->gui_module) : 0;
3864-
const gboolean display_wavelet_scale =
3865-
(g && gui_active) ? g->display_wavelet_scale : FALSE;
3863+
const gboolean display_wavelet_scale = g && dt_iop_has_focus(self) ? g->display_wavelet_scale : FALSE;
38663864

38673865
// we will do all the clone, heal, etc on the input image,
38683866
// this way the source for one algorithm can be the destination from a previous one
@@ -3881,8 +3879,7 @@ void process(dt_iop_module_t *self,
38813879
usr_data.mask_display = FALSE;
38823880
usr_data.suppress_mask = (g
38833881
&& g->suppress_mask
3884-
&& self->dev->gui_attached
3885-
&& (self == self->dev->gui_module)
3882+
&& dt_iop_has_focus(self)
38863883
&& (piece->pipe == self->dev->full.pipe));
38873884
usr_data.display_scale = p->curr_scale;
38883885

@@ -3898,8 +3895,8 @@ void process(dt_iop_module_t *self,
38983895

38993896
// check if this module should expose mask.
39003897
if((piece->pipe->type & DT_DEV_PIXELPIPE_FULL) && g
3901-
&& (g->mask_display || display_wavelet_scale) && self->dev->gui_attached
3902-
&& (self == self->dev->gui_module) && (piece->pipe == self->dev->full.pipe))
3898+
&& (g->mask_display || display_wavelet_scale)
3899+
&& dt_iop_has_focus(self) && (piece->pipe == self->dev->full.pipe))
39033900
{
39043901
for(size_t j = 0; j < (size_t)roi_rt->width * roi_rt->height * 4; j += 4)
39053902
in_retouch[j + 3] = 0.f;
@@ -3913,7 +3910,7 @@ void process(dt_iop_module_t *self,
39133910
if(piece->pipe->type & DT_DEV_PIXELPIPE_FULL)
39143911
{
39153912
// check if the image support this number of scales
3916-
if(gui_active)
3913+
if(dt_iop_has_focus(self))
39173914
{
39183915
const int max_scales = dwt_get_max_scale(dwt_p);
39193916
if(dwt_p->scales > max_scales)
@@ -4671,8 +4668,7 @@ int process_cl(dt_iop_module_t *self,
46714668
retouch_user_data_t usr_data = { 0 };
46724669
dwt_params_cl_t *dwt_p = NULL;
46734670

4674-
const gboolean gui_active = (self->dev) ? (self == self->dev->gui_module) : FALSE;
4675-
const gboolean display_wavelet_scale = g && gui_active ? g->display_wavelet_scale : FALSE;
4671+
const gboolean display_wavelet_scale = g && dt_iop_has_focus(self) ? g->display_wavelet_scale : FALSE;
46764672

46774673
// we will do all the clone, heal, etc on the input image, this way
46784674
// the source for one algorithm can be the destination from a
@@ -4696,8 +4692,7 @@ int process_cl(dt_iop_module_t *self,
46964692
usr_data.mask_display = FALSE;
46974693
usr_data.suppress_mask = (g
46984694
&& g->suppress_mask
4699-
&& self->dev->gui_attached
4700-
&& (self == self->dev->gui_module)
4695+
&& dt_iop_has_focus(self)
47014696
&& (piece->pipe == self->dev->full.pipe));
47024697
usr_data.display_scale = p->curr_scale;
47034698

@@ -4718,8 +4713,7 @@ int process_cl(dt_iop_module_t *self,
47184713
// check if this module should expose mask.
47194714
if((piece->pipe->type & DT_DEV_PIXELPIPE_FULL)
47204715
&& g && g->mask_display
4721-
&& self->dev->gui_attached
4722-
&& (self == self->dev->gui_module)
4716+
&& dt_iop_has_focus(self)
47234717
&& (piece->pipe == self->dev->full.pipe))
47244718
{
47254719
const int kernel = gd->kernel_retouch_clear_alpha;
@@ -4738,7 +4732,7 @@ int process_cl(dt_iop_module_t *self,
47384732
if(piece->pipe->type & DT_DEV_PIXELPIPE_FULL)
47394733
{
47404734
// check if the image support this number of scales
4741-
if(gui_active)
4735+
if(dt_iop_has_focus(self))
47424736
{
47434737
const int max_scales = dwt_get_max_scale_cl(dwt_p);
47444738
if(dwt_p->scales > max_scales)

0 commit comments

Comments
 (0)