From 31daa83f2b507e287725a7cf648ae5b51effbabf Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Sun, 14 Jan 2024 16:58:34 +0100 Subject: #877: Formatting, comments, debug output --- src/Fl_Shared_Image.cxx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/Fl_Shared_Image.cxx') diff --git a/src/Fl_Shared_Image.cxx b/src/Fl_Shared_Image.cxx index 21aedd40a..4a9f91393 100644 --- a/src/Fl_Shared_Image.cxx +++ b/src/Fl_Shared_Image.cxx @@ -222,7 +222,7 @@ void Fl_Shared_Image::release() { Fl_Shared_Image *the_original = NULL; #ifdef SHIM_DEBUG - printf("----> Fl_Shared_Image::release() %016x\n", this); + printf("----> Fl_Shared_Image::release() %d %s %d %d\n", original_, name_, w(), h()); print_pool(); #endif @@ -230,12 +230,13 @@ void Fl_Shared_Image::release() { refcount_ --; if (refcount_ > 0) return; + // If this image is not the original, find the original image and make sure + // to delete its reference counter as well at the end of this method. if (!original()) { Fl_Shared_Image *o = find(name()); - if (o && o->original() && o!=this) { - the_original = o; - } if (o) { + if (o->original() && o!=this && o->refcount_>1) + the_original = o; // mark to release later o->release(); // release from find() operation } } @@ -262,12 +263,14 @@ void Fl_Shared_Image::release() { alloc_images_ = 0; } #ifdef SHIM_DEBUG - printf("<---- Fl_Shared_Image::release() %016x\n", this); + printf("<---- Fl_Shared_Image::release() %d %s %d %d\n", original_, name_, w(), h()); print_pool(); printf("\n"); #endif + + // Release one reference count in the original image as well. if (the_original) - the_original->release(); // release as a reference to this copy of the image + the_original->release(); } /** Reloads the shared image from disk. */ -- cgit v1.2.3