From 97673116d6a7ff254c5d56d54c6cfb05002f751c Mon Sep 17 00:00:00 2001 From: raveit65 Date: Sun, 8 Jan 2017 20:13:48 +0100 Subject: Fontviewer: font-model, cancel previous loading when refreshing font list This should help in case a refresh is requested before the previous operation completes. Currently, we seem to be crashing when that happens, see https://bugzilla.redhat.com/show_bug.cgi?id=870753 taken from: https://git.gnome.org/browse/gnome-font-viewer/commit/?id=47fbb29 --- font-viewer/font-model.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'font-viewer/font-model.c') diff --git a/font-viewer/font-model.c b/font-viewer/font-model.c index c7b79d5c..45077e39 100644 --- a/font-viewer/font-model.c +++ b/font-viewer/font-model.c @@ -50,6 +50,7 @@ struct _FontViewModelPrivate { GList *monitors; GdkPixbuf *fallback_icon; + GCancellable *cancellable; }; enum { @@ -360,11 +361,17 @@ load_font_infos (GIOSchedulerJob *job, gint i; GList *font_infos = NULL; + if (g_cancellable_is_cancelled (cancellable)) + return FALSE; + for (i = 0; i < self->priv->font_list->nfont; i++) { FontInfoData *font_info; FcChar8 *file; gchar *font_name; + if (g_cancellable_is_cancelled (cancellable)) + break; + FcPatternGetString (self->priv->font_list->fonts[i], FC_FILE, 0, &file); font_name = font_utils_get_font_name_for_file (self->priv->library, (const gchar *) file); @@ -382,8 +389,11 @@ load_font_infos (GIOSchedulerJob *job, data->self = g_object_ref (self); data->font_infos = font_infos; - g_io_scheduler_job_send_to_mainloop_async (job, font_infos_loaded, - data, load_font_infos_data_free); + if (g_cancellable_is_cancelled (cancellable)) + load_font_infos_data_free (data); + else + g_io_scheduler_job_send_to_mainloop_async (job, font_infos_loaded, + data, load_font_infos_data_free); return FALSE; } @@ -396,8 +406,13 @@ ensure_font_list (FontViewModel *self) FcObjectSet *os; if (self->priv->font_list) { - FcFontSetDestroy (self->priv->font_list); - self->priv->font_list = NULL; + FcFontSetDestroy (self->priv->font_list); + self->priv->font_list = NULL; + } + + if (self->priv->cancellable) { + g_cancellable_cancel (self->priv->cancellable); + g_clear_object (&self->priv->cancellable); } gtk_list_store_clear (GTK_LIST_STORE (self)); @@ -418,7 +433,7 @@ ensure_font_list (FontViewModel *self) return; g_io_scheduler_push_job (load_font_infos, self, NULL, - G_PRIORITY_DEFAULT, NULL); + G_PRIORITY_DEFAULT, self->priv->cancellable); } static gboolean @@ -557,6 +572,11 @@ font_view_model_finalize (GObject *obj) { FontViewModel *self = FONT_VIEW_MODEL (obj); + if (self->priv->cancellable) { + g_cancellable_cancel (self->priv->cancellable); + g_clear_object (&self->priv->cancellable); + } + if (self->priv->font_list) { FcFontSetDestroy (self->priv->font_list); self->priv->font_list = NULL; -- cgit v1.2.1