From f803f1552cc65f4879da4d1cf7cc502423023ab1 Mon Sep 17 00:00:00 2001 From: electron128 Date: Thu, 21 May 2015 09:31:26 +0000 Subject: [PATCH] reduce memory corruption in voip plugin git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8282 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- TODO.txt | 1 + retroshare-gui/src/gui/common/RsButtonOnText.cpp | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/TODO.txt b/TODO.txt index 3bf8063ed..e235f869c 100644 --- a/TODO.txt +++ b/TODO.txt @@ -276,6 +276,7 @@ H [ ] get rid of the old cache system (remove CacheStrapper, CacheSource, GUI H [ ] enable circles for channels/posted/forums E [ ] enable people dialog +E [ ] fix RSButtonOnText::eventFilter, and fix all places where RSButtonOnText gets deleted GXS H [ ] add the ability to use anonymous identities into circles. Needs new distribution model using items encrypted for multiple GXS keys. diff --git a/retroshare-gui/src/gui/common/RsButtonOnText.cpp b/retroshare-gui/src/gui/common/RsButtonOnText.cpp index fe05f8b0f..124c3cde5 100644 --- a/retroshare-gui/src/gui/common/RsButtonOnText.cpp +++ b/retroshare-gui/src/gui/common/RsButtonOnText.cpp @@ -6,6 +6,7 @@ #include #include #include +#include RSButtonOnText::RSButtonOnText(QWidget *parent) : QPushButton(parent) @@ -81,6 +82,12 @@ RSButtonOnText::~RSButtonOnText() bool RSButtonOnText::eventFilter(QObject *obj, QEvent *event) { + // comment electron: + // the guard is here, because someone deletes this object in callbacks(slots) called from here + // the QPointer can detect this + // but this is bad practice, because it hides the root cause for the problem, + // which is the deletion of objects in their own signals + // TODO: better use the Qt function deleteLater QPointer guard(this); QPoint point; if (isEventForThis(obj, event, point)) { @@ -94,7 +101,7 @@ bool RSButtonOnText::eventFilter(QObject *obj, QEvent *event) ,QPoint(1,1),Qt::LeftButton,Qt::LeftButton,0); QPushButton::mousePressEvent(mouseEvent); delete mouseEvent; - _pressed = true; + if (guard) _pressed = true; //if (guard) emit pressed(); if (guard) updateImage(); } @@ -103,7 +110,7 @@ bool RSButtonOnText::eventFilter(QObject *obj, QEvent *event) ,QPoint(1,1),Qt::LeftButton,Qt::LeftButton,0); QPushButton::mouseReleaseEvent(mouseEvent); delete mouseEvent; - _pressed = false; + if (guard) _pressed = false; //if (guard) emit released(); //if (guard) emit clicked(); //if (guard) if (isCheckable()) emit clicked(QPushButton::isChecked()); @@ -119,7 +126,7 @@ bool RSButtonOnText::eventFilter(QObject *obj, QEvent *event) //QPushButton::setDown(true); if (guard) emit mouseEnter(); } - _mouseOver = true; + if (guard) _mouseOver = true; if (guard) updateImage(); } } else { @@ -145,6 +152,9 @@ bool RSButtonOnText::eventFilter(QObject *obj, QEvent *event) } } + if(!guard) + std::cerr << "BIG FAT WARNING from RSButtonOnText::eventFilter(): i was deleted in my own event handler. This is bad practice. Please make a patch and use deleteLater to delay deletion." << std::endl; + // pass the event on to the parent class return QWidget::eventFilter(obj, event); }