From bc3ed05a47d86ee3ec78d166df17d1f446f2d0cd Mon Sep 17 00:00:00 2001 From: Vladimir Nadvornik Date: Sat, 12 Nov 2011 11:36:18 +0100 Subject: [PATCH] call size signal indirectly via idle_call image_loader_size_cb is called from a second thread, so it can't use any gtk functions directly or via signals this fixes random crashes in gtk code introduced by commit e24281e5 --- src/image-load.c | 32 ++++++++++++++++++++++++++++---- src/image-load.h | 4 ++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/image-load.c b/src/image-load.c index 167ca89e..aaec9f97 100644 --- a/src/image-load.c +++ b/src/image-load.c @@ -92,6 +92,8 @@ static void image_loader_init(GTypeInstance *instance, gpointer g_class) il->requested_width = 0; il->requested_height = 0; + il->actual_width = 0; + il->actual_height = 0; il->shrunk = FALSE; il->can_destroy = TRUE; @@ -280,6 +282,19 @@ static gboolean image_loader_emit_percent_cb(gpointer data) return FALSE; } +static gboolean image_loader_emit_size_cb(gpointer data) +{ + gint width, height; + ImageLoader *il = data; + g_mutex_lock(il->data_mutex); + width = il->actual_width; + height = il->actual_height; + g_mutex_unlock(il->data_mutex); + g_signal_emit(il, signals[SIGNAL_SIZE], 0, width, height); + return FALSE; +} + + /* DONE and ERROR are emited only once, thus they can have normal priority PERCENT and AREA_READY should be processed ASAP */ @@ -299,6 +314,11 @@ static void image_loader_emit_percent(ImageLoader *il) g_idle_add_full(G_PRIORITY_HIGH, image_loader_emit_percent_cb, il, NULL); } +static void image_loader_emit_size(ImageLoader *il) +{ + g_idle_add_full(G_PRIORITY_HIGH, image_loader_emit_size_cb, il, NULL); +} + /* this function expects that il->data_mutex is locked by caller */ static void image_loader_emit_area_ready(ImageLoader *il, guint x, guint y, guint w, guint h) { @@ -444,10 +464,12 @@ static void image_loader_size_cb(gpointer loader, gint n; g_mutex_lock(il->data_mutex); + il->actual_width = width; + il->actual_height = height; if (il->requested_width < 1 || il->requested_height < 1) { g_mutex_unlock(il->data_mutex); - g_signal_emit(il, signals[SIGNAL_SIZE], 0, width, height); + image_loader_emit_size(il); return; } g_mutex_unlock(il->data_mutex); @@ -463,7 +485,7 @@ static void image_loader_size_cb(gpointer loader, if (!scale) { - g_signal_emit(il, signals[SIGNAL_SIZE], 0, width, height); + image_loader_emit_size(il); return; } @@ -486,12 +508,14 @@ static void image_loader_size_cb(gpointer loader, if (nw < 1) nw = 1; } + il->actual_width = nw; + il->actual_height = nh; il->backend.set_size(loader, nw, nh); il->shrunk = TRUE; } - g_mutex_unlock(il->data_mutex); - g_signal_emit(il, signals[SIGNAL_SIZE], 0, nw, nh); + g_mutex_unlock(il->data_mutex); + image_loader_emit_size(il); } static void image_loader_stop_loader(ImageLoader *il) diff --git a/src/image-load.h b/src/image-load.h index 90e1260e..c2e9f184 100644 --- a/src/image-load.h +++ b/src/image-load.h @@ -66,6 +66,10 @@ struct _ImageLoader gint requested_width; gint requested_height; + + gint actual_width; + gint actual_height; + gboolean shrunk; gboolean done; -- 2.20.1