diff --git a/ChangeLog b/ChangeLog index fe89164..f837fdc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2923,3 +2923,12 @@ that'll work sanely. I think this is more sane behaviour, having tested it in feh and imlib2_view, but feel free to disagree ;-) +_______________________________________________ + +Wed Jul 12 22:20:53 PDT 2000 +(KainX) + +It's generally a good idea to increment the reference count when you +implement reference counting. This should fix the mysterious problems +people have been having with Imlib2 stealing pixmaps out from under +Eterm. diff --git a/src/draw.c b/src/draw.c index 1434af9..3f35cd0 100644 --- a/src/draw.c +++ b/src/draw.c @@ -31,6 +31,11 @@ __imlib_CreatePixmapsForImage(Display *d, Drawable w, Visual *v, int depth, *p = ip->pixmap; if (m) *m = ip->mask; + ip->references++; +#ifdef DEBUG_CACHE + fprintf(stderr, "[Imlib2] Match found in cache. Reference count is %d, pixmap 0x%08x, mask 0x%08x\n", + ip->references, ip->pixmap, ip->mask); +#endif return 2; } if (p) @@ -71,6 +76,10 @@ __imlib_CreatePixmapsForImage(Display *d, Drawable w, Visual *v, int depth, ip->pixmap = pmap; ip->mask = mask; __imlib_AddImagePixmapToCache(ip); +#ifdef DEBUG_CACHE + fprintf(stderr, "[Imlib2] Created pixmap. Reference count is %d, pixmap 0x%08x, mask 0x%08x\n", + ip->references, ip->pixmap, ip->mask); +#endif return 1; } diff --git a/src/image.c b/src/image.c index 7478b59..4b08816 100644 --- a/src/image.c +++ b/src/image.c @@ -360,6 +360,10 @@ __imlib_ProduceImagePixmap(void) void __imlib_ConsumeImagePixmap(ImlibImagePixmap *ip) { +#ifdef DEBUG_CACHE + fprintf(stderr, "[Imlib2] Deleting pixmap. Reference count is %d, pixmap 0x%08x, mask 0x%08x\n", + ip->references, ip->pixmap, ip->mask); +#endif if (ip->pixmap) XFreePixmap(ip->display, ip->pixmap); if (ip->mask) @@ -1126,7 +1130,13 @@ __imlib_FindImlibImagePixmapByID(Display *d, Pixmap p) { /* if all the pixmap ID & Display match */ if ((ip->pixmap == p) && (ip->display == d)) - return ip; + { +#ifdef DEBUG_CACHE + fprintf(stderr, "[Imlib2] Match found. Reference count is %d, pixmap 0x%08x, mask 0x%08x\n", + ip->references, ip->pixmap, ip->mask); +#endif + return ip; + } ip = ip->next; } return NULL; @@ -1170,13 +1180,22 @@ __imlib_FreePixmap(Display *d, Pixmap p) { /* dereference it by one */ ip->references--; +#ifdef DEBUG_CACHE + fprintf(stderr, "[Imlib2] Reference count is now %d for pixmap 0x%08x\n", + ip->references, ip->pixmap); +#endif /* if it becaume 0 reference count - clean the cache up */ if (ip->references == 0) __imlib_CleanupImagePixmapCache(); } } else - XFreePixmap(d, p); + { +#ifdef DEBUG_CACHE + fprintf(stderr, "[Imlib2] Pixmap 0x%08x not found. Freeing.\n", p); + XFreePixmap(d, p); +#endif + } } /* mark all pixmaps generated from this image as diryt so the cache code */ diff --git a/src/rend.c b/src/rend.c index f8a3321..9d1dc65 100644 --- a/src/rend.c +++ b/src/rend.c @@ -112,7 +112,7 @@ __imlib_RenderImage(Display *d, ImlibImage *im, if (!xim) { __imlib_FreeScaleInfo(scaleinfo); - free(back); + if (back) free(back); return; } /* do a double check in 24/32bpp */ @@ -125,7 +125,7 @@ __imlib_RenderImage(Display *d, ImlibImage *im, { __imlib_ConsumeXImage(d, xim); __imlib_FreeScaleInfo(scaleinfo); - free(back); + if (back) free(back); return; } } @@ -140,7 +140,7 @@ __imlib_RenderImage(Display *d, ImlibImage *im, if (m) __imlib_ConsumeXImage(d, mxim); __imlib_FreeScaleInfo(scaleinfo); - free(back); + if (back) free(back); return; } }