Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: proper fix for history-paste crashes #17455

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/control/jobs.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of darktable,
Copyright (C) 2009-2023 darktable developers.
Copyright (C) 2009-2024 darktable developers.

darktable is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -53,6 +53,7 @@ typedef struct _dt_job_t

char description[DT_CONTROL_DESCRIPTION_LEN];
dt_view_type_flags_t view_creator;
gboolean is_synchronous;
} _dt_job_t;

/** check if two jobs are to be considered equal. a simple memcmp won't work since the mutexes probably won't
Expand Down Expand Up @@ -153,6 +154,16 @@ dt_view_type_flags_t dt_control_job_get_view_creator(const dt_job_t *job)
return job->view_creator;
}

gboolean dt_control_job_is_synchronous(const dt_job_t *job)
{
return job->is_synchronous;
}

void dt_control_job_set_synchronous(dt_job_t *job, gboolean sync)
{
job->is_synchronous = sync;
}

void dt_control_job_dispose(_dt_job_t *job)
{
if(!job) return;
Expand Down Expand Up @@ -413,6 +424,7 @@ gboolean dt_control_add_job(dt_control_t *control,
{
// whatever we are adding here won't be scheduled as the system isn't running. execute it synchronous instead.
dt_pthread_mutex_lock(&job->wait_mutex); // is that even needed?
dt_control_job_set_synchronous(job, TRUE);
_control_job_execute(job);
dt_pthread_mutex_unlock(&job->wait_mutex);

Expand Down
2 changes: 2 additions & 0 deletions src/control/jobs.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ gboolean dt_control_add_job(struct dt_control_t *control, dt_job_queue_t queue_i
gboolean dt_control_add_job_res(struct dt_control_t *s, dt_job_t *job, int32_t res);

dt_view_type_flags_t dt_control_job_get_view_creator(const dt_job_t *job);
gboolean dt_control_job_is_synchronous(const dt_job_t *job);
void dt_control_job_set_synchronous(dt_job_t *job, gboolean sync);

int32_t dt_control_get_threadid();

Expand Down
63 changes: 40 additions & 23 deletions src/control/jobs/control_jobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1537,8 +1537,13 @@ static int32_t dt_control_refresh_exif_run(dt_job_t *job)

static inline gboolean _safe_history_job_on_imgid(dt_job_t *job, dt_imgid_t imgid)
{
return dt_control_job_get_view_creator(job) == DT_VIEW_DARKROOM
|| (darktable.develop && darktable.develop->image_storage.id != imgid);
// it is safe to run a history-modifying operation if:
// 1. we are running synchronously
// 2. we are not editing an image in darkroom, or
// 3. we are not modifying the image being edited
return dt_control_job_is_synchronous(job)
|| !darktable.develop
|| darktable.develop->image_storage.id != imgid;
}

static int32_t _control_paste_history_job_run(dt_job_t *job)
Expand Down Expand Up @@ -2179,18 +2184,38 @@ void dt_control_refresh_exif()
NULL, PROGRESS_CANCELLABLE, FALSE));
}

static void _add_history_job(GList *imgs, const char *title, dt_job_execute_callback execute)
{
if(!imgs || !execute)
return;
GList *link = darktable.develop ? g_list_find(imgs,GINT_TO_POINTER(darktable.develop->image_storage.id)) : NULL;
if(link)
{
// remove the image in darkroom center view from the list of images to be processed, and
// run it synchronously by itself
imgs = g_list_remove_link(imgs, link);
dt_control_add_job(darktable.control, DT_JOB_QUEUE_SYNCHRONOUS,
dt_control_generic_images_job_create(execute, title, 0,
link, PROGRESS_BLOCKING, FALSE));
}
// if there are any images left in the list after removing the darkroom image, process them asynchronously
// but block user interactions other than cancellation
if(imgs)
{
dt_control_add_job(darktable.control, DT_JOB_QUEUE_USER_FG,
dt_control_generic_images_job_create(execute, title, 0,
imgs, PROGRESS_BLOCKING, FALSE));
}
}

void dt_control_paste_history(GList *imgs)
{
if(!dt_is_valid_imgid(darktable.view_manager->copy_paste.copied_imageid))
{
g_list_free(imgs);
return;
}
dt_job_queue_t queue = g_list_shorter_than(imgs,4) ? DT_JOB_QUEUE_SYNCHRONOUS : DT_JOB_QUEUE_USER_FG;
dt_control_add_job(darktable.control, queue,
dt_control_generic_images_job_create(&_control_paste_history_job_run,
N_("paste history"), 0,
imgs, PROGRESS_BLOCKING, FALSE));
_add_history_job(imgs, N_("paste history"), &_control_paste_history_job_run);
}

void dt_control_paste_parts_history(GList *imgs)
Expand All @@ -2208,40 +2233,32 @@ void dt_control_paste_parts_history(GList *imgs)

if(res == GTK_RESPONSE_OK)
{
dt_job_queue_t queue = g_list_shorter_than(imgs,4) ? DT_JOB_QUEUE_SYNCHRONOUS : DT_JOB_QUEUE_USER_FG;
dt_control_add_job(darktable.control, queue,
dt_control_generic_images_job_create(&_control_paste_history_job_run,
N_("paste history"), 0,
imgs, PROGRESS_BLOCKING, FALSE));
_add_history_job(imgs, N_("paste history"), &_control_paste_history_job_run);
}
else
g_list_free(imgs);
}

void dt_control_compress_history(GList *imgs)
{
if(!imgs)
return;
if(g_list_is_singleton(imgs))
{
(void)dt_history_compress(GPOINTER_TO_INT(imgs->data));
g_list_free(imgs);
return;
}
dt_control_add_job(darktable.control, DT_JOB_QUEUE_USER_FG,
dt_control_generic_images_job_create(&_control_compress_history_job_run,
N_("compress history"), 0,
imgs, PROGRESS_BLOCKING, FALSE));
_add_history_job(imgs, N_("compress history"), &_control_compress_history_job_run);
}

void dt_control_discard_history(GList *imgs)
{
if(!imgs)
if(g_list_is_singleton(imgs))
{
dt_history_delete(GPOINTER_TO_INT(imgs->data), TRUE);
g_list_free(imgs);
return;
dt_control_add_job(darktable.control, DT_JOB_QUEUE_USER_FG,
dt_control_generic_images_job_create(&_control_discard_history_job_run,
N_("discard history"), 0,
imgs, PROGRESS_BLOCKING, FALSE));
}
_add_history_job(imgs, N_("discard history"), &_control_discard_history_job_run);
}

static dt_control_image_enumerator_t *dt_control_export_alloc()
Expand Down
Loading