From ce04447c7a98b675071f565b0dfe38aedcf41fd9 Mon Sep 17 00:00:00 2001 From: Hombre Date: Tue, 3 Sep 2019 22:18:20 +0200 Subject: [PATCH] Fix crash while rotating several thumbnails in File Browser Fix issue #4858 and possibly #5310 --- rtengine/rtthumbnail.cc | 28 ++++++++++++---------- rtgui/filebrowserentry.cc | 43 +++++++++++++++++++++++++++++++--- rtgui/thumbbrowserentrybase.cc | 9 ++++--- rtgui/thumbnail.h | 10 ++++---- 4 files changed, 66 insertions(+), 24 deletions(-) diff --git a/rtengine/rtthumbnail.cc b/rtengine/rtthumbnail.cc index 5efb75d48..1ffaf939a 100644 --- a/rtengine/rtthumbnail.cc +++ b/rtengine/rtthumbnail.cc @@ -1483,6 +1483,7 @@ IImage8* Thumbnail::processImage (const procparams::ProcParams& params, eSensorT delete labView; delete baseImg; + /* // calculate scale if (params.coarse.rotate == 90 || params.coarse.rotate == 270) { myscale = scale * thumbImg->getWidth() / fh; @@ -1491,19 +1492,20 @@ IImage8* Thumbnail::processImage (const procparams::ProcParams& params, eSensorT } myscale = 1.0 / myscale; - /* // apply crop - if (params.crop.enabled) { - int ix = 0; - for (int i=0; i(params.crop.y+params.crop.h)/myscale || j(params.crop.x+params.crop.w)/myscale) { - readyImg->data[ix++] /= 3; - readyImg->data[ix++] /= 3; - readyImg->data[ix++] /= 3; - } - else - ix += 3; - }*/ + // apply crop + if (params.crop.enabled) { + int ix = 0; + for (int i=0; i(params.crop.y+params.crop.h)/myscale || j(params.crop.x+params.crop.w)/myscale) { + readyImg->data[ix++] /= 3; + readyImg->data[ix++] /= 3; + readyImg->data[ix++] /= 3; + } + else + ix += 3; + } + */ return readyImg; } diff --git a/rtgui/filebrowserentry.cc b/rtgui/filebrowserentry.cc index 8b518335c..87a48a7ea 100644 --- a/rtgui/filebrowserentry.cc +++ b/rtgui/filebrowserentry.cc @@ -255,17 +255,20 @@ void FileBrowserEntry::_updateImage(rtengine::IImage8* img, double s, const rten const bool resize = !preview || prew != img->getWidth(); prew = img->getWidth (); - GThreadLock lock; - // Check if image has been rotated since last time rotated = preview && newLandscape != landscape; if (resize) { - delete [] preview; + if (preview) { + delete [] preview; + } preview = new guint8 [prew * preh * 3]; } memcpy(preview, img->getData(), prew * preh * 3); + { + GThreadLock lock; updateBackBuffer (); + } } landscape = newLandscape; @@ -318,24 +321,36 @@ bool FileBrowserEntry::motionNotify (int x, int y) cropParams->y = action_y + (y - press_y) / scale; cropParams->h += oy - cropParams->y; cropgl->cropHeight1Resized (cropParams->x, cropParams->y, cropParams->w, cropParams->h, crop_custom_ratio); + { + MYREADERLOCK(l, lockRW); updateBackBuffer (); + } parent->redrawNeeded (this); } else if (state == SResizeH2 && cropgl) { cropParams->h = action_y + (y - press_y) / scale; cropgl->cropHeight2Resized (cropParams->x, cropParams->y, cropParams->w, cropParams->h, crop_custom_ratio); + { + MYREADERLOCK(l, lockRW); updateBackBuffer (); + } parent->redrawNeeded (this); } else if (state == SResizeW1 && cropgl) { int ox = cropParams->x; cropParams->x = action_x + (x - press_x) / scale; cropParams->w += ox - cropParams->x; cropgl->cropWidth1Resized (cropParams->x, cropParams->y, cropParams->w, cropParams->h, crop_custom_ratio); + { + MYREADERLOCK(l, lockRW); updateBackBuffer (); + } parent->redrawNeeded (this); } else if (state == SResizeW2 && cropgl) { cropParams->w = action_x + (x - press_x) / scale; cropgl->cropWidth2Resized (cropParams->x, cropParams->y, cropParams->w, cropParams->h, crop_custom_ratio); + { + MYREADERLOCK(l, lockRW); updateBackBuffer (); + } parent->redrawNeeded (this); } else if (state == SResizeTL && cropgl) { int ox = cropParams->x; @@ -345,7 +360,10 @@ bool FileBrowserEntry::motionNotify (int x, int y) cropParams->y = action_y + (y - press_y) / scale; cropParams->h += oy - cropParams->y; cropgl->cropTopLeftResized (cropParams->x, cropParams->y, cropParams->w, cropParams->h, crop_custom_ratio); + { + MYREADERLOCK(l, lockRW); updateBackBuffer (); + } parent->redrawNeeded (this); } else if (state == SResizeTR && cropgl) { cropParams->w = action_x + (x - press_x) / scale; @@ -353,7 +371,10 @@ bool FileBrowserEntry::motionNotify (int x, int y) cropParams->y = action_y + (y - press_y) / scale; cropParams->h += oy - cropParams->y; cropgl->cropTopRightResized (cropParams->x, cropParams->y, cropParams->w, cropParams->h, crop_custom_ratio); + { + MYREADERLOCK(l, lockRW); updateBackBuffer (); + } parent->redrawNeeded (this); } else if (state == SResizeBL && cropgl) { int ox = cropParams->x; @@ -361,19 +382,28 @@ bool FileBrowserEntry::motionNotify (int x, int y) cropParams->w += ox - cropParams->x; cropParams->h = action_y + (y - press_y) / scale; cropgl->cropBottomLeftResized (cropParams->x, cropParams->y, cropParams->w, cropParams->h, crop_custom_ratio); + { + MYREADERLOCK(l, lockRW); updateBackBuffer (); + } parent->redrawNeeded (this); } else if (state == SResizeBR && cropgl) { cropParams->w = action_x + (x - press_x) / scale; cropParams->h = action_y + (y - press_y) / scale; cropgl->cropBottomRightResized (cropParams->x, cropParams->y, cropParams->w, cropParams->h, crop_custom_ratio); + { + MYREADERLOCK(l, lockRW); updateBackBuffer (); + } parent->redrawNeeded (this); } else if (state == SCropMove && cropgl) { cropParams->x = action_x + (x - press_x) / scale; cropParams->y = action_y + (y - press_y) / scale; cropgl->cropMoved (cropParams->x, cropParams->y, cropParams->w, cropParams->h); + { + MYREADERLOCK(l, lockRW); updateBackBuffer (); + } parent->redrawNeeded (this); } else if (state == SCropSelecting && cropgl) { int cx1 = press_x, cy1 = press_y; @@ -396,7 +426,10 @@ bool FileBrowserEntry::motionNotify (int x, int y) cropParams->h = cy1 - cy2 + 1; } + { + MYREADERLOCK(l, lockRW); updateBackBuffer (); + } parent->redrawNeeded (this); } @@ -564,6 +597,7 @@ bool FileBrowserEntry::releaseNotify (int button, int type, int bstate, int x, i bool FileBrowserEntry::onArea (CursorArea a, int x, int y) { + MYREADERLOCK(l, lockRW); if (!drawable || !preview) { return false; } @@ -764,6 +798,8 @@ void FileBrowserEntry::drawStraightenGuide (Cairo::RefPtr cr) int y2 = action_y; int x2 = action_x; + { + MYREADERLOCK(l, lockRW); if (x2 < prex + ofsX + startx) { y2 = y1 - (double)(y1 - y2) * (x1 - (prex + ofsX + startx)) / (x1 - x2); x2 = prex + ofsX + startx; @@ -779,6 +815,7 @@ void FileBrowserEntry::drawStraightenGuide (Cairo::RefPtr cr) x2 = x1 - (double)(x1 - x2) * (y1 - (preh + prey + ofsY + starty - 1)) / (y1 - y2); y2 = preh + prey + ofsY + starty - 1; } + } cr->set_line_width (1.5); cr->set_source_rgb (1.0, 1.0, 1.0); diff --git a/rtgui/thumbbrowserentrybase.cc b/rtgui/thumbbrowserentrybase.cc index e660e794b..4dacb1adf 100644 --- a/rtgui/thumbbrowserentrybase.cc +++ b/rtgui/thumbbrowserentrybase.cc @@ -494,6 +494,7 @@ void ThumbBrowserEntryBase::resize (int h) height = h; int old_preh = preh; + int old_prew = prew; // dimensions of the button set int bsw = 0, bsh = 0; @@ -555,9 +556,11 @@ void ThumbBrowserEntryBase::resize (int h) width = bsw + 2 * sideMargin + 2 * borderWidth; } - if (preh != old_preh) { - delete [] preview; - preview = nullptr; + if (preh != old_preh || prew != old_prew) { // if new thumbnail height or new orientation + if (preview) { + delete [] preview; + preview = nullptr; + } refreshThumbnailImage (); } else if (backBuffer) { backBuffer->setDirty(true); // This will force a backBuffer update on queue_draw diff --git a/rtgui/thumbnail.h b/rtgui/thumbnail.h index 0bcdd470a..e3196778c 100644 --- a/rtgui/thumbnail.h +++ b/rtgui/thumbnail.h @@ -49,17 +49,17 @@ class Thumbnail rtengine::Thumbnail* tpp; int tw, th; // dimensions of timgdata (it stores tpp->width and tpp->height in processed mode for simplicity) float imgRatio; // hack to avoid rounding error -// double scale; // portion of the sizes of the processed thumbnail image and the full scale image +// double scale; // portion of the sizes of the processed thumbnail image and the full scale image const std::unique_ptr pparams; bool pparamsValid; bool imageLoading; // these are the data of the result image of the last getthumbnailimage call (for caching purposes) - unsigned char* lastImg; - int lastW; - int lastH; - double lastScale; + unsigned char* lastImg; // pointer to the processed and scaled base ImageIO image + int lastW; // non rotated width of the cached ImageIO image + int lastH; // non rotated height of the cached ImageIO image + double lastScale; // scale of the cached ImageIO image // exif & date/time strings Glib::ustring exifString;