From ab2c1f23e9392526b824c1a60a06b641f91ea0d8 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 7 Mar 2020 20:39:10 +0100 Subject: [PATCH 1/6] attempt to solve GXS data access problems in new blocking API --- libretroshare/src/retroshare/rsgxsifacehelper.h | 16 ++++++++++++---- libretroshare/src/services/p3gxscircles.cc | 10 ++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/libretroshare/src/retroshare/rsgxsifacehelper.h b/libretroshare/src/retroshare/rsgxsifacehelper.h index 60f317de1..99d029361 100644 --- a/libretroshare/src/retroshare/rsgxsifacehelper.h +++ b/libretroshare/src/retroshare/rsgxsifacehelper.h @@ -274,8 +274,7 @@ struct RsGxsIfaceHelper { mTokenService.requestGroupStatistic(token, grpId); } /// @see RsTokenService::cancelRequest - bool cancelRequest(uint32_t token) - { return mTokenService.cancelRequest(token); } + bool cancelRequest(uint32_t token) { return mTokenService.cancelRequest(token); } /** * @deprecated @@ -291,12 +290,21 @@ protected: * @param[in] token token associated to the request caller is waiting for * @param[in] maxWait maximum waiting time in milliseconds * @param[in] checkEvery time in millisecond between status checks + * @param[in] auto_delete_if_unsuccessful delete the request when it fails. This avoid leaving useless pending requests in the queue that would slow down additional calls. */ RsTokenService::GxsRequestStatus waitToken( uint32_t token, std::chrono::milliseconds maxWait = std::chrono::milliseconds(2000), - std::chrono::milliseconds checkEvery = std::chrono::milliseconds(20)) - { return mTokenService.waitToken(token, maxWait, checkEvery); } + std::chrono::milliseconds checkEvery = std::chrono::milliseconds(20), + bool auto_delete_if_unsuccessful=true) + { + RsTokenService::GxsRequestStatus res = mTokenService.waitToken(token, maxWait, checkEvery); + + if(res != RsTokenService::COMPLETE && auto_delete_if_unsuccessful) + cancelRequest(token); + + return res; + } private: RsGxsIface& mGxs; diff --git a/libretroshare/src/services/p3gxscircles.cc b/libretroshare/src/services/p3gxscircles.cc index 8d5e878c1..7c1892cd1 100644 --- a/libretroshare/src/services/p3gxscircles.cc +++ b/libretroshare/src/services/p3gxscircles.cc @@ -278,8 +278,9 @@ bool p3GxsCircles::getCirclesSummaries(std::list& circles) uint32_t token; RsTokReqOptions opts; opts.mReqType = GXS_REQUEST_TYPE_GROUP_META; - if( !requestGroupInfo(token, opts) - || waitToken(token) != RsTokenService::COMPLETE ) return false; + if( !requestGroupInfo(token, opts) || waitToken(token) != RsTokenService::COMPLETE ) + cancelRequest(token); + return getGroupSummary(token, circles); } @@ -289,8 +290,9 @@ bool p3GxsCircles::getCirclesInfo( const std::list& circlesIds, uint32_t token; RsTokReqOptions opts; opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA; - if( !requestGroupInfo(token, opts, circlesIds) - || waitToken(token) != RsTokenService::COMPLETE ) return false; + if( !requestGroupInfo(token, opts, circlesIds) || waitToken(token) != RsTokenService::COMPLETE ) + return false; + return getGroupData(token, circlesInfo); } From dc3c3488df1f9a7146a5f4d18bf4c548715de006 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 9 Mar 2020 21:01:55 +0100 Subject: [PATCH 2/6] added blocking API for createComment() in GxsCommentService and removed token queue from GxsCreateCommentDialog --- libretroshare/src/retroshare/rsgxscommon.h | 4 +++- libretroshare/src/services/p3gxschannels.h | 4 ++-- libretroshare/src/services/p3gxscommon.cc | 2 +- libretroshare/src/services/p3gxscommon.h | 2 +- libretroshare/src/services/p3photoservice.h | 2 +- libretroshare/src/services/p3posted.h | 8 ++++++- .../src/gui/Posted/PostedCreatePostDialog.cpp | 3 +-- .../src/gui/Posted/PostedCreatePostDialog.h | 1 - .../src/gui/gxs/GxsCommentTreeWidget.cpp | 4 ++-- .../src/gui/gxs/GxsCreateCommentDialog.cpp | 23 ++++++------------- .../src/gui/gxs/GxsCreateCommentDialog.h | 4 +--- 11 files changed, 26 insertions(+), 31 deletions(-) diff --git a/libretroshare/src/retroshare/rsgxscommon.h b/libretroshare/src/retroshare/rsgxscommon.h index 126c2b51f..96253448e 100644 --- a/libretroshare/src/retroshare/rsgxscommon.h +++ b/libretroshare/src/retroshare/rsgxscommon.h @@ -157,7 +157,9 @@ struct RsGxsCommentService virtual bool getRelatedComments( uint32_t token, std::vector &comments ) = 0; - virtual bool createNewComment(uint32_t &token, RsGxsComment &comment) = 0; + virtual bool createNewComment(uint32_t &token, const RsGxsComment &comment) = 0; // async API + virtual bool createComment(RsGxsComment& comment) = 0; // blocking API. Updates comment with new metadata. + virtual bool createNewVote(uint32_t &token, RsGxsVote &vote) = 0; virtual bool acknowledgeComment( diff --git a/libretroshare/src/services/p3gxschannels.h b/libretroshare/src/services/p3gxschannels.h index 40ca193e6..c83fbc4df 100644 --- a/libretroshare/src/services/p3gxschannels.h +++ b/libretroshare/src/services/p3gxschannels.h @@ -140,7 +140,7 @@ virtual bool getChannelDownloadDirectory(const RsGxsGroupId &groupId, std::strin std::vector &msgs ) override { return mCommentService->getGxsRelatedComments(token, msgs); } - virtual bool createNewComment(uint32_t &token, RsGxsComment &msg) override + virtual bool createNewComment(uint32_t &token, const RsGxsComment &msg) override { return mCommentService->createGxsComment(token, msg); } @@ -277,7 +277,7 @@ virtual bool ExtraFileRemove(const RsFileHash &hash); /// @deprecated Implementation of @see RsGxsChannels::createComment RS_DEPRECATED_FOR(createCommentV2) - bool createComment(RsGxsComment& comment) override; + bool createComment(RsGxsComment &comment) override; /// @deprecated Implementation of @see RsGxsChannels::createVote RS_DEPRECATED_FOR(createVoteV2) diff --git a/libretroshare/src/services/p3gxscommon.cc b/libretroshare/src/services/p3gxscommon.cc index a0682acd9..38f6f3cc0 100644 --- a/libretroshare/src/services/p3gxscommon.cc +++ b/libretroshare/src/services/p3gxscommon.cc @@ -425,7 +425,7 @@ double p3GxsCommentService::calculateBestScore(int upVotes, int downVotes) /********************************************************************************************/ -bool p3GxsCommentService::createGxsComment(uint32_t &token, RsGxsComment &msg) +bool p3GxsCommentService::createGxsComment(uint32_t &token, const RsGxsComment &msg) { #ifdef DEBUG_GXSCOMMON std::cerr << "p3GxsCommentService::createGxsComment() GroupId: " << msg.mMeta.mGroupId; diff --git a/libretroshare/src/services/p3gxscommon.h b/libretroshare/src/services/p3gxscommon.h index 469fa3426..4b25c826e 100644 --- a/libretroshare/src/services/p3gxscommon.h +++ b/libretroshare/src/services/p3gxscommon.h @@ -66,7 +66,7 @@ class p3GxsCommentService: public GxsTokenQueue bool getGxsCommentData(const uint32_t &token, std::vector &msgs); bool getGxsRelatedComments(const uint32_t &token, std::vector &msgs); - bool createGxsComment(uint32_t &token, RsGxsComment &msg); + bool createGxsComment(uint32_t &token, const RsGxsComment &msg); bool createGxsVote(uint32_t &token, RsGxsVote &msg); // Special Acknowledge. diff --git a/libretroshare/src/services/p3photoservice.h b/libretroshare/src/services/p3photoservice.h index 7bbffd2b0..9712233a6 100644 --- a/libretroshare/src/services/p3photoservice.h +++ b/libretroshare/src/services/p3photoservice.h @@ -85,7 +85,7 @@ public: return mCommentService->getGxsRelatedComments(token, msgs); } - virtual bool createNewComment(uint32_t &token, RsGxsComment &msg) override + virtual bool createNewComment(uint32_t &token, const RsGxsComment &msg) override { return mCommentService->createGxsComment(token, msg); } diff --git a/libretroshare/src/services/p3posted.h b/libretroshare/src/services/p3posted.h index 04c7503e1..a0802722c 100644 --- a/libretroshare/src/services/p3posted.h +++ b/libretroshare/src/services/p3posted.h @@ -96,10 +96,16 @@ virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgI std::vector &msgs ) { return mCommentService->getGxsRelatedComments(token, msgs); } - virtual bool createNewComment(uint32_t &token, RsGxsComment &msg) + virtual bool createNewComment(uint32_t &token, const RsGxsComment &msg) override { return mCommentService->createGxsComment(token, msg); } + virtual bool createComment(RsGxsComment& msg) override + { + uint32_t token; + + return mCommentService->createGxsComment(token, msg) && waitToken(token) == RsTokenService::COMPLETE ; + } virtual bool createNewVote(uint32_t &token, RsGxsVote &msg) { diff --git a/retroshare-gui/src/gui/Posted/PostedCreatePostDialog.cpp b/retroshare-gui/src/gui/Posted/PostedCreatePostDialog.cpp index 71094b91b..ede58cdbc 100644 --- a/retroshare-gui/src/gui/Posted/PostedCreatePostDialog.cpp +++ b/retroshare-gui/src/gui/Posted/PostedCreatePostDialog.cpp @@ -47,7 +47,7 @@ PostedCreatePostDialog::PostedCreatePostDialog(TokenQueue* tokenQ, RsPosted *posted, const RsGxsGroupId& grpId, QWidget *parent): QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint), - mTokenQueue(tokenQ), mPosted(posted), mGrpId(grpId), + mPosted(posted), mGrpId(grpId), ui(new Ui::PostedCreatePostDialog) { ui->setupUi(this); @@ -176,7 +176,6 @@ void PostedCreatePostDialog::createPost() uint32_t token; mPosted->createPost(token, post); -// mTokenQueue->queueRequest(token, TOKENREQ_MSGINFO, RS_TOKREQ_ANSTYPE_ACK, TOKEN_USER_TYPE_POST); accept(); } diff --git a/retroshare-gui/src/gui/Posted/PostedCreatePostDialog.h b/retroshare-gui/src/gui/Posted/PostedCreatePostDialog.h index 6e11c795b..f8c5c08cc 100644 --- a/retroshare-gui/src/gui/Posted/PostedCreatePostDialog.h +++ b/retroshare-gui/src/gui/Posted/PostedCreatePostDialog.h @@ -62,7 +62,6 @@ private: QString mLink; QString mNotes; - TokenQueue* mTokenQueue; RsPosted* mPosted; RsGxsGroupId mGrpId; diff --git a/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.cpp b/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.cpp index 296ce68c8..31edb4a0f 100644 --- a/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.cpp +++ b/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.cpp @@ -307,7 +307,7 @@ void GxsCommentTreeWidget::banUser() void GxsCommentTreeWidget::makeComment() { - GxsCreateCommentDialog pcc(mTokenQueue, mCommentService, std::make_pair(mGroupId,mLatestMsgId), mLatestMsgId, this); + GxsCreateCommentDialog pcc(mCommentService, std::make_pair(mGroupId,mLatestMsgId), mLatestMsgId, this); pcc.exec(); } @@ -316,7 +316,7 @@ void GxsCommentTreeWidget::replyToComment() RsGxsGrpMsgIdPair msgId; msgId.first = mGroupId; msgId.second = mCurrentCommentMsgId; - GxsCreateCommentDialog pcc(mTokenQueue, mCommentService, msgId, mLatestMsgId, this); + GxsCreateCommentDialog pcc(mCommentService, msgId, mLatestMsgId, this); pcc.loadComment(mCurrentCommentText, mCurrentCommentAuthor, mCurrentCommentAuthorId); pcc.exec(); diff --git a/retroshare-gui/src/gui/gxs/GxsCreateCommentDialog.cpp b/retroshare-gui/src/gui/gxs/GxsCreateCommentDialog.cpp index 5158d8981..dd3f2f97c 100644 --- a/retroshare-gui/src/gui/gxs/GxsCreateCommentDialog.cpp +++ b/retroshare-gui/src/gui/gxs/GxsCreateCommentDialog.cpp @@ -26,20 +26,16 @@ #include #include -GxsCreateCommentDialog::GxsCreateCommentDialog(TokenQueue *tokQ, RsGxsCommentService *service, - const RsGxsGrpMsgIdPair &parentId, const RsGxsMessageId& threadId, QWidget *parent) : +GxsCreateCommentDialog::GxsCreateCommentDialog(RsGxsCommentService *service, const RsGxsGrpMsgIdPair &parentId, const RsGxsMessageId& threadId, QWidget *parent) : QDialog(parent), - ui(new Ui::GxsCreateCommentDialog), mTokenQueue(tokQ), mCommentService(service), mParentId(parentId), mThreadId(threadId) + ui(new Ui::GxsCreateCommentDialog), mCommentService(service), mParentId(parentId), mThreadId(threadId) { ui->setupUi(this); connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(createComment())); connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(close())); - /* fill in the available OwnIds for signing */ ui->idChooser->loadIds(IDCHOOSER_ID_REQUIRED, RsGxsId()); - - } void GxsCreateCommentDialog::loadComment(const QString &msgText, const QString &msgAuthor, const RsGxsId &msgAuthorId) @@ -80,9 +76,9 @@ void GxsCreateCommentDialog::createComment() std::cerr << "ThreadId : " << comment.mMeta.mThreadId << std::endl; std::cerr << "ParentId : " << comment.mMeta.mParentId << std::endl; - RsGxsId authorId; - switch (ui->idChooser->getChosenId(authorId)) { + switch (ui->idChooser->getChosenId(authorId)) + { case GxsIdChooser::KnowId: case GxsIdChooser::UnKnowId: comment.mMeta.mAuthorId = authorId; @@ -96,17 +92,12 @@ void GxsCreateCommentDialog::createComment() std::cerr << "GxsCreateCommentDialog::createComment() ERROR GETTING AuthorId!"; std::cerr << std::endl; - int ret = QMessageBox::information(this, tr("Comment Signing Error"), - tr("You need to create an Identity\n" - "before you can comment"), - QMessageBox::Ok); - Q_UNUSED(ret) + QMessageBox::information(this, tr("Comment Signing Error"), tr("You need to create an Identity\n" "before you can comment"), QMessageBox::Ok); return; - }//switch (ui->idChooser->getChosenId(authorId)) + } uint32_t token; - mCommentService->createNewComment(token, comment); - mTokenQueue->queueRequest(token, TOKENREQ_MSGINFO, RS_TOKREQ_ANSTYPE_ACK, 0); + mCommentService->createComment(comment); close(); } diff --git a/retroshare-gui/src/gui/gxs/GxsCreateCommentDialog.h b/retroshare-gui/src/gui/gxs/GxsCreateCommentDialog.h index 8267e448a..967649179 100644 --- a/retroshare-gui/src/gui/gxs/GxsCreateCommentDialog.h +++ b/retroshare-gui/src/gui/gxs/GxsCreateCommentDialog.h @@ -36,8 +36,7 @@ class GxsCreateCommentDialog : public QDialog Q_OBJECT public: - explicit GxsCreateCommentDialog(TokenQueue* tokQ, RsGxsCommentService *service, - const RsGxsGrpMsgIdPair& parentId, const RsGxsMessageId& threadId, QWidget *parent = 0); + explicit GxsCreateCommentDialog(RsGxsCommentService *service, const RsGxsGrpMsgIdPair& parentId, const RsGxsMessageId& threadId, QWidget *parent = 0); ~GxsCreateCommentDialog(); void loadComment(const QString &msgText, const QString &msgAuthor, const RsGxsId &msgAuthorId); @@ -47,7 +46,6 @@ private slots: private: Ui::GxsCreateCommentDialog *ui; - TokenQueue *mTokenQueue; RsGxsCommentService *mCommentService; RsGxsGrpMsgIdPair mParentId; From aa05348d5511d905475dea1903114d1b1dd675ce Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 11 Mar 2020 22:41:19 +0100 Subject: [PATCH 3/6] removed token queue from PostedCreatePostDialog --- retroshare-gui/src/gui/Posted/PostedCreatePostDialog.cpp | 3 +-- retroshare-gui/src/gui/Posted/PostedCreatePostDialog.h | 4 +--- retroshare-gui/src/gui/Posted/PostedListWidget.cpp | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/retroshare-gui/src/gui/Posted/PostedCreatePostDialog.cpp b/retroshare-gui/src/gui/Posted/PostedCreatePostDialog.cpp index ede58cdbc..fada00020 100644 --- a/retroshare-gui/src/gui/Posted/PostedCreatePostDialog.cpp +++ b/retroshare-gui/src/gui/Posted/PostedCreatePostDialog.cpp @@ -28,7 +28,6 @@ #include "ui_PostedCreatePostDialog.h" #include "util/misc.h" -#include "util/TokenQueue.h" #include "util/RichTextEdit.h" #include "gui/feeds/SubFileItem.h" #include "util/rsdir.h" @@ -45,7 +44,7 @@ #define VIEW_IMAGE 2 #define VIEW_LINK 3 -PostedCreatePostDialog::PostedCreatePostDialog(TokenQueue* tokenQ, RsPosted *posted, const RsGxsGroupId& grpId, QWidget *parent): +PostedCreatePostDialog::PostedCreatePostDialog(RsPosted *posted, const RsGxsGroupId& grpId, QWidget *parent): QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint), mPosted(posted), mGrpId(grpId), ui(new Ui::PostedCreatePostDialog) diff --git a/retroshare-gui/src/gui/Posted/PostedCreatePostDialog.h b/retroshare-gui/src/gui/Posted/PostedCreatePostDialog.h index f8c5c08cc..64ab35566 100644 --- a/retroshare-gui/src/gui/Posted/PostedCreatePostDialog.h +++ b/retroshare-gui/src/gui/Posted/PostedCreatePostDialog.h @@ -26,8 +26,6 @@ #include "retroshare/rsposted.h" #include "util/RichTextEdit.h" -class TokenQueue; - namespace Ui { class PostedCreatePostDialog; } @@ -41,7 +39,7 @@ public: * @param tokenQ parent callee token * @param posted */ - explicit PostedCreatePostDialog(TokenQueue* tokenQ, RsPosted* posted, const RsGxsGroupId& grpId, QWidget *parent = 0); + explicit PostedCreatePostDialog(RsPosted* posted, const RsGxsGroupId& grpId, QWidget *parent = 0); ~PostedCreatePostDialog(); private: diff --git a/retroshare-gui/src/gui/Posted/PostedListWidget.cpp b/retroshare-gui/src/gui/Posted/PostedListWidget.cpp index 6d0c852a5..a35490028 100644 --- a/retroshare-gui/src/gui/Posted/PostedListWidget.cpp +++ b/retroshare-gui/src/gui/Posted/PostedListWidget.cpp @@ -250,7 +250,7 @@ void PostedListWidget::newPost() return; } - PostedCreatePostDialog *cp = new PostedCreatePostDialog(mTokenQueue, rsPosted, groupId(), this); + PostedCreatePostDialog *cp = new PostedCreatePostDialog(rsPosted, groupId(), this); cp->show(); /* window will destroy itself! */ From a02bb0acb6f57705ac362198d1cb28ed95adb4ab Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 11 Mar 2020 22:41:57 +0100 Subject: [PATCH 4/6] added cancel in waitToken in rstokenservice --- libretroshare/src/retroshare/rstokenservice.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libretroshare/src/retroshare/rstokenservice.h b/libretroshare/src/retroshare/rstokenservice.h index a7da6ee32..e48df29ad 100644 --- a/libretroshare/src/retroshare/rstokenservice.h +++ b/libretroshare/src/retroshare/rstokenservice.h @@ -232,7 +232,8 @@ public: RsTokenService::GxsRequestStatus waitToken( uint32_t token, std::chrono::milliseconds maxWait = std::chrono::milliseconds(500), - std::chrono::milliseconds checkEvery = std::chrono::milliseconds(2)) + std::chrono::milliseconds checkEvery = std::chrono::milliseconds(2), + bool auto_delete_if_unsuccessful=true) { #if defined(__ANDROID__) && (__ANDROID_API__ < 24) auto wkStartime = std::chrono::steady_clock::now(); @@ -241,12 +242,13 @@ LLwaitTokenBeginLabel: #endif auto timeout = std::chrono::steady_clock::now() + maxWait; auto st = requestStatus(token); - while( !(st == RsTokenService::FAILED || st >= RsTokenService::COMPLETE) - && std::chrono::steady_clock::now() < timeout ) + while( !(st == RsTokenService::FAILED || st >= RsTokenService::COMPLETE) && std::chrono::steady_clock::now() < timeout ) { std::this_thread::sleep_for(checkEvery); st = requestStatus(token); } + if(st != RsTokenService::COMPLETE && auto_delete_if_unsuccessful) + cancelRequest(token); #if defined(__ANDROID__) && (__ANDROID_API__ < 24) /* Work around for very slow/old android devices, we don't expect this From 230eca985fb466ac9d5878deccc24e311330fd29 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 11 Mar 2020 22:42:34 +0100 Subject: [PATCH 5/6] reverted unnecessary cancel of tokens after waitToken in p3gxscircles --- libretroshare/src/services/p3gxscircles.cc | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/libretroshare/src/services/p3gxscircles.cc b/libretroshare/src/services/p3gxscircles.cc index 7c1892cd1..c00532b82 100644 --- a/libretroshare/src/services/p3gxscircles.cc +++ b/libretroshare/src/services/p3gxscircles.cc @@ -279,9 +279,12 @@ bool p3GxsCircles::getCirclesSummaries(std::list& circles) RsTokReqOptions opts; opts.mReqType = GXS_REQUEST_TYPE_GROUP_META; if( !requestGroupInfo(token, opts) || waitToken(token) != RsTokenService::COMPLETE ) - cancelRequest(token); - - return getGroupSummary(token, circles); + { + std::cerr << "Cannot get circles summary. Token queue is overloaded?" << std::endl; + return false; + } + else + return getGroupSummary(token, circles); } bool p3GxsCircles::getCirclesInfo( const std::list& circlesIds, @@ -291,9 +294,12 @@ bool p3GxsCircles::getCirclesInfo( const std::list& circlesIds, RsTokReqOptions opts; opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA; if( !requestGroupInfo(token, opts, circlesIds) || waitToken(token) != RsTokenService::COMPLETE ) + { + std::cerr << "Cannot get circle info. Token queue is overloaded?" << std::endl; return false; - - return getGroupData(token, circlesInfo); + } + else + return getGroupData(token, circlesInfo); } bool p3GxsCircles::getCircleRequests( const RsGxsGroupId& circleId, From 70d0c7b1b31211757e074b25d7f087facb597ffa Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 12 Mar 2020 22:12:06 +0100 Subject: [PATCH 6/6] quick workaround to avoid crash in loadCircles() --- retroshare-gui/src/gui/Identity/IdDialog.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/retroshare-gui/src/gui/Identity/IdDialog.cpp b/retroshare-gui/src/gui/Identity/IdDialog.cpp index d59b5bcf2..75d1dde7c 100644 --- a/retroshare-gui/src/gui/Identity/IdDialog.cpp +++ b/retroshare-gui/src/gui/Identity/IdDialog.cpp @@ -59,6 +59,8 @@ * #define ID_DEBUG 1 *****/ +#define QT_BUG_CRASH_IN_TAKECHILD_WORKAROUND 1 + // Data Requests. #define IDDIALOG_IDLIST 1 #define IDDIALOG_IDDETAILS 2 @@ -586,6 +588,17 @@ void IdDialog::loadCircles(const std::list& groupInfo) mStateHelper->setActive(CIRCLESDIALOG_GROUPMETA, true); +#ifdef QT_BUG_CRASH_IN_TAKECHILD_WORKAROUND + // These 3 lines are normally not needed. But apparently a bug (in Qt ??) causes Qt to crash when takeChild() is called. If we remove everything from the + // tree widget before updating it, takeChild() is never called, but the all tree is filled again from scratch. This is less efficient obviously, and + // also collapses the tree. Because it is a *temporary* fix, I dont take the effort to save open/collapsed items yet. If we cannot find a proper way to fix + // this, then we'll need to implement the two missing functions to save open/collapsed items. + + ui->treeWidget_membership->clear(); + mExternalOtherCircleItem = NULL ; + mExternalBelongingCircleItem = NULL ; +#endif + /* add the top level item */ //QTreeWidgetItem *personalCirclesItem = new QTreeWidgetItem(); //personalCirclesItem->setText(0, tr("Personal Circles"));