From 76fddb29afa7cf3b93194511fcd0ec074c9e0458 Mon Sep 17 00:00:00 2001 From: Phenom Date: Wed, 16 Mar 2016 19:05:22 +0100 Subject: [PATCH] Fix delete in PictureFlow --- .../src/gui/People/PeopleDialog.cpp | 6 +- retroshare-gui/src/gui/common/PictureFlow.cpp | 56 +++++++++---------- retroshare-gui/src/retroshare-gui.pro | 1 + 3 files changed, 30 insertions(+), 33 deletions(-) diff --git a/retroshare-gui/src/gui/People/PeopleDialog.cpp b/retroshare-gui/src/gui/People/PeopleDialog.cpp index d7947832f..4fcdb82f3 100644 --- a/retroshare-gui/src/gui/People/PeopleDialog.cpp +++ b/retroshare-gui/src/gui/People/PeopleDialog.cpp @@ -82,11 +82,11 @@ PeopleDialog::PeopleDialog(QWidget *parent) {//First Get Item created in Qt Designer for Internal int count = idInternal->children().count(); - for (int curs = 0; curs < count; ++curs){ + for (int curs = 0; curs < count; ++curs){ QObject *obj = idInternal->children().at(curs); - QWidget *wid = qobject_cast(obj); + QWidget *wid = qobject_cast(obj); if (wid) _flowLayoutInt->addWidget(wid); - }//for (int curs = 0; curs < count; ++curs) + }//for (int curs = 0; curs < count; ++curs) }//End First Get Item created in Qt Designer for Internal pictureFlowWidgetExternal->setAcceptDrops(true); diff --git a/retroshare-gui/src/gui/common/PictureFlow.cpp b/retroshare-gui/src/gui/common/PictureFlow.cpp index 4f6287ea2..ad10fb2e8 100644 --- a/retroshare-gui/src/gui/common/PictureFlow.cpp +++ b/retroshare-gui/src/gui/common/PictureFlow.cpp @@ -293,8 +293,9 @@ PictureFlowState::PictureFlowState(): PictureFlowState::~PictureFlowState() { - for(int i = 0; i < (int)slideImages.count(); ++i) - delete slideImages[i]; + while (! slideImages.isEmpty()) { + delete slideImages.takeFirst(); + } } // readjust the settings, call this when slide dimension is changed @@ -482,7 +483,7 @@ PictureFlowSoftwareRenderer::~PictureFlowSoftwareRenderer() { surfaceCache.clear(); buffer = QImage(); - delete blankSurface; + if (blankSurface) delete blankSurface; } void PictureFlowSoftwareRenderer::paint() @@ -516,6 +517,7 @@ void PictureFlowSoftwareRenderer::init() return; surfaceCache.clear(); + if (blankSurface) delete blankSurface; blankSurface = 0; size = widget->size(); @@ -687,7 +689,7 @@ QImage* PictureFlowSoftwareRenderer::surface(int slideIndex) bool empty = img ? img->isNull() : true; if(empty) { surfaceCache.remove(key); - imageHash.remove(slideIndex); + delete imageHash.take(slideIndex); if(!blankSurface) { int sw = state->slideWidth; int sh = state->slideHeight; @@ -723,29 +725,28 @@ QImage* PictureFlowSoftwareRenderer::surface(int slideIndex) return blankSurface; }//if(empty) +#ifdef PICTUREFLOW_QT2 + if(img == imageHash[slideIndex]) +#endif +#ifdef PICTUREFLOW_QT3 + bool exist = imageHash.find(slideIndex) != imageHash.end(); + if(exist) + if(img == imageHash.find(slideIndex).data()) +#endif #ifdef PICTUREFLOW_QT4 bool exist = imageHash.contains(slideIndex); if(exist) if(img == imageHash.find(slideIndex).value()) #endif -#ifdef PICTUREFLOW_QT3 - bool exist = imageHash.find(slideIndex) != imageHash.end(); - if(exist) - if(img == imageHash.find(slideIndex).data()) -#endif -#ifdef PICTUREFLOW_QT2 - if(img == imageHash[slideIndex]) -#endif - if(surfaceCache.contains(key)) - return surfaceCache[key]; + if(surfaceCache.contains(key)) + return surfaceCache[key]; - QImage* sr = prepareSurface(img, state->slideWidth, state->slideHeight, bgcolor, state->reflectionEffect); - QImage *sr_copy = new QImage(*sr) ; + QImage* sr = prepareSurface(img, state->slideWidth, state->slideHeight, bgcolor, state->reflectionEffect); - surfaceCache.insert(key, sr); // this takes ownership on sr. So we can't use it afterwards + surfaceCache.insert(key, sr); // QCache takes ownership on sr. And delete it when removed. imageHash.insert(slideIndex, img); - return sr_copy; + return sr; } // Renders a slide to offscreen buffer. Returns a rect of the rendered area. @@ -756,7 +757,7 @@ QRect PictureFlowSoftwareRenderer::renderSlide(const SlideInfo &slide, int col1, if(!blend) return QRect(); - QImage* src = surface(slide.slideIndex); + QImage* src = surface(slide.slideIndex); // src is owned by surfaceCache(QCache) don't delete it. if(!src) return QRect(); @@ -787,11 +788,8 @@ QRect PictureFlowSoftwareRenderer::renderSlide(const SlideInfo &slide, int col1, PFreal dist = distance * PFREAL_ONE; int xi = qMax((PFreal)0, ((w*PFREAL_ONE/2) + fdiv(xs*h, dist+ys)) >> PFREAL_SHIFT); - if(xi >= w) - { - delete src ; - return rect; - } + if(xi >= w) + return rect; bool flag = false; rect.setLeft(xi); @@ -860,8 +858,7 @@ QRect PictureFlowSoftwareRenderer::renderSlide(const SlideInfo &slide, int col1, }//for(int x = qMax(xi, col1); x <= col2; ++x) rect.setTop(0); - rect.setBottom(h-1); - delete src ; + rect.setBottom(h-1); return rect; } @@ -1107,10 +1104,9 @@ void PictureFlow::setCenterIndex(int index) void PictureFlow::clear() { - int c = d->state->slideImages.count(); - for(int i = 0; i < c; ++i) - delete d->state->slideImages[i]; - d->state->slideImages.resize(0); + while (! d->state->slideImages.isEmpty()) { + delete d->state->slideImages.takeFirst(); + } d->state->reset(); triggerRender(); diff --git a/retroshare-gui/src/retroshare-gui.pro b/retroshare-gui/src/retroshare-gui.pro index d78bdb831..4386b9fd7 100644 --- a/retroshare-gui/src/retroshare-gui.pro +++ b/retroshare-gui/src/retroshare-gui.pro @@ -1176,6 +1176,7 @@ identities { gxscircles { DEFINES += RS_USE_CIRCLES +# DEFINES += RS_USE_NEW_PEOPLE_DIALOG HEADERS += \ gui/Circles/CirclesDialog.h \