From e67e8c3a42c4950df21b88f20d7d158bf0badee7 Mon Sep 17 00:00:00 2001 From: Phillip Berndt Date: Thu, 14 Apr 2016 11:17:25 +0200 Subject: [PATCH] Bugfix: Prevent crash in lazy mode if many of the first images fail to load The actual bugfix is the compare-to-one-instead-of-zero. The usleep() is a (hopefully temporary) mitigation against a race which I cannot pinpoint yet that prevents the main window from being shown sometimes in that case. --- README.markdown | 3 +++ pqiv.c | 5 +++-- pqiv.h | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.markdown b/README.markdown index 2ab52a2..e75e2fc 100644 --- a/README.markdown +++ b/README.markdown @@ -128,6 +128,9 @@ Known bugs Changelog --------- +pqiv 2.5.1 + * Prevent a crash in --lazy-load mode if many images fail to load + pqiv 2.5 * Added a configure option to build the backends as shared libraries * Added a configure option to remove unneeded/unwanted features diff --git a/pqiv.c b/pqiv.c index 2685598..edce557 100644 --- a/pqiv.c +++ b/pqiv.c @@ -1838,7 +1838,7 @@ gboolean image_loader_load_single(BOSNode *node, gboolean called_from_main) {/*{ if(node == current_file_node) { current_file_node = next_file(); if(current_file_node == node) { - if(bostree_node_count(file_tree) > 0) { + if(bostree_node_count(file_tree) > 1) { // This can be triggered in shuffle mode if images are deleted and the end of // a shuffle cycle is reached, such that next_file() starts a new one. Fall // back to display the first image. See bug #35 in github. @@ -1949,6 +1949,7 @@ gpointer image_loader_thread(gpointer user_data) {/*{{{*/ current_image_drawn = FALSE; gdk_threads_add_idle((GSourceFunc)image_loaded_handler, node); } + D_LOCK(file_tree); bostree_node_weak_unref(file_tree, node); D_UNLOCK(file_tree); @@ -1979,7 +1980,7 @@ gboolean initialize_image_loader() {/*{{{*/ } current_file_node = bostree_node_weak_ref(current_file_node); D_UNLOCK(file_tree); - while(!image_loader_load_single(current_file_node, TRUE) && bostree_node_count(file_tree) > 0); + while(!image_loader_load_single(current_file_node, TRUE) && bostree_node_count(file_tree) > 0) usleep(10000); if(bostree_node_count(file_tree) == 0) { return FALSE; } diff --git a/pqiv.h b/pqiv.h index 0d74a33..01eee90 100644 --- a/pqiv.h +++ b/pqiv.h @@ -29,7 +29,7 @@ #include "lib/bostree.h" #ifndef PQIV_VERSION -#define PQIV_VERSION "2.5" +#define PQIV_VERSION "2.5.1" #endif #define FILE_FLAGS_ANIMATION (guint)(1)