summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-03-11 21:27:45 +0100
committerGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-03-11 21:27:45 +0100
commitdcabb2614f08eb07a118c545e8df7af8cf898148 (patch)
treeffd7bca37cbe6183412ce2a348772501422cea0c
parent5f0cf616e4614b060ceb2e68b8401ce2d0fb7bad (diff)
fixed few crashbugs in coverart code
-rw-r--r--plugins/gtkui/coverart.c36
-rw-r--r--plugins/gtkui/plcommon.c1
2 files changed, 28 insertions, 9 deletions
diff --git a/plugins/gtkui/coverart.c b/plugins/gtkui/coverart.c
index 4089e44d..b7e92645 100644
--- a/plugins/gtkui/coverart.c
+++ b/plugins/gtkui/coverart.c
@@ -25,6 +25,8 @@
#include "../artwork/artwork.h"
#include "gtkui.h"
+#pragma GCC optimize("O0")
+
#define trace(...) { fprintf(stderr, __VA_ARGS__); }
//#define trace(...)
@@ -110,6 +112,7 @@ loading_thread (void *none) {
deadbeef->mutex_unlock (mutex);
while (!terminate && queue) {
int cache_min = 0;
+ deadbeef->mutex_lock (mutex);
for (int i = 0; i < CACHE_SIZE; i++) {
if (!cache[i].pixbuf) {
cache_min = i;
@@ -121,6 +124,22 @@ loading_thread (void *none) {
}
}
}
+ if (cache_min != -1) {
+ if (cache[cache_min].pixbuf) {
+ g_object_unref (cache[cache_min].pixbuf);
+ cache[cache_min].pixbuf = NULL;
+ }
+ if (cache[cache_min].fname) {
+ free (cache[cache_min].fname);
+ cache[cache_min].fname = NULL;
+ }
+ }
+ deadbeef->mutex_unlock (mutex);
+ if (cache_min == -1) {
+ trace ("coverart pixbuf cache overflow, waiting...\n");
+ usleep (500000);
+ continue;
+ }
trace ("loading image %s\n", queue->fname);
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file (queue->fname, NULL);
@@ -157,16 +176,14 @@ loading_thread (void *none) {
pixbuf = scaled;
}
}
- if (cache[cache_min].pixbuf) {
- g_object_unref (cache[cache_min].pixbuf);
- }
- if (cache[cache_min].fname) {
- free (cache[cache_min].fname);
+ if (cache_min != -1) {
+ deadbeef->mutex_lock (mutex);
+ cache[cache_min].pixbuf = pixbuf;
+ cache[cache_min].fname = strdup (queue->fname);
+ gettimeofday (&cache[cache_min].tm, NULL);
+ cache[cache_min].width = queue->width;
+ deadbeef->mutex_unlock (mutex);
}
- cache[cache_min].pixbuf = pixbuf;
- cache[cache_min].fname = strdup (queue->fname);
- gettimeofday (&cache[cache_min].tm, NULL);
- cache[cache_min].width = queue->width;
queue_pop ();
g_idle_add (redraw_playlist_cb, NULL);
}
@@ -197,6 +214,7 @@ get_pixbuf (const char *fname, int width) {
if (cache[i].pixbuf) {
if (!strcmp (fname, cache[i].fname) && cache[i].width == width) {
gettimeofday (&cache[i].tm, NULL);
+ g_object_ref (cache[i].pixbuf);
deadbeef->mutex_unlock (mutex);
return cache[i].pixbuf;
}
diff --git a/plugins/gtkui/plcommon.c b/plugins/gtkui/plcommon.c
index 7e3aca11..eed3858a 100644
--- a/plugins/gtkui/plcommon.c
+++ b/plugins/gtkui/plcommon.c
@@ -110,6 +110,7 @@ void draw_column_data (DdbListview *listview, GdkDrawable *drawable, DdbListview
gdk_draw_pixbuf (drawable, GTK_WIDGET (listview)->style->white_gc, pixbuf, 0, sy, x + ART_PADDING_HORZ, art_y, pw, ph, GDK_RGB_DITHER_NONE, 0, 0);
// gdk_draw_rectangle (drawable, GTK_WIDGET (listview)->style->black_gc, FALSE, x + ART_PADDING_HORZ, art_y, pw, ph);
}
+ g_object_unref (pixbuf);
}
}
}