From 46e8db7d6df1578cba9b3dae1cf50daa00766196 Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 3 Aug 2023 20:22:30 +0200 Subject: [PATCH] fixing crash when deleting forum feed items while loading --- retroshare-gui/src/gui/Posted/PostedItem.cpp | 2 +- .../src/gui/feeds/GxsForumMsgItem.cpp | 23 +++++++++++++++++++ .../src/gui/feeds/GxsForumMsgItem.h | 4 ++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/retroshare-gui/src/gui/Posted/PostedItem.cpp b/retroshare-gui/src/gui/Posted/PostedItem.cpp index 06b585614..8f1cddf7d 100644 --- a/retroshare-gui/src/gui/Posted/PostedItem.cpp +++ b/retroshare-gui/src/gui/Posted/PostedItem.cpp @@ -74,7 +74,7 @@ BasePostedItem::BasePostedItem( FeedHolder *feedHolder, uint32_t feedId BasePostedItem::~BasePostedItem() { - auto timeout = std::chrono::steady_clock::now() + std::chrono::milliseconds(200); + auto timeout = std::chrono::steady_clock::now() + std::chrono::milliseconds(200); while( (mIsLoadingGroup || mIsLoadingMessage || mIsLoadingComment) && std::chrono::steady_clock::now() < timeout) { diff --git a/retroshare-gui/src/gui/feeds/GxsForumMsgItem.cpp b/retroshare-gui/src/gui/feeds/GxsForumMsgItem.cpp index eedb4ae20..81b026d27 100644 --- a/retroshare-gui/src/gui/feeds/GxsForumMsgItem.cpp +++ b/retroshare-gui/src/gui/feeds/GxsForumMsgItem.cpp @@ -83,6 +83,19 @@ GxsForumMsgItem::GxsForumMsgItem(FeedHolder *feedHolder, uint32_t feedId, const GxsForumMsgItem::~GxsForumMsgItem() { + auto timeout = std::chrono::steady_clock::now() + std::chrono::milliseconds(300); + + while( (mLoadingGroup || mLoadingMessage || mLoadingSetAsRead || mLoadingParentMessage) + && std::chrono::steady_clock::now() < timeout) + { + RsDbg() << __PRETTY_FUNCTION__ << " is Waiting for " + << (mLoadingGroup ? "Group " : "") + << (mLoadingMessage ? "Message " : "") + << (mLoadingParentMessage ? "Parent message " : "") + << (mLoadingSetAsRead ? "Set as read" : "") + << "loading." << std::endl; + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } delete(ui); } @@ -167,6 +180,8 @@ QString GxsForumMsgItem::groupName() void GxsForumMsgItem::loadGroup() { + mLoadingGroup = true; + RsThread::async([this]() { // 1 - get group data @@ -199,6 +214,7 @@ void GxsForumMsgItem::loadGroup() * after a blocking call to RetroShare API complete */ setGroup(group); + mLoadingGroup = false; }, this ); }); @@ -210,6 +226,7 @@ void GxsForumMsgItem::loadMessage() std::cerr << "GxsForumMsgItem::loadMessage(): messageId=" << messageId() << " groupId=" << groupId() ; std::cerr << std::endl; #endif + mLoadingMessage = true; RsThread::async([this]() { @@ -244,6 +261,7 @@ void GxsForumMsgItem::loadMessage() * after a blocking call to RetroShare API complete */ setMessage(msg); + mLoadingMessage = false; }, this ); }); @@ -255,6 +273,7 @@ void GxsForumMsgItem::loadParentMessage(const RsGxsMessageId& parent_msg) std::cerr << "GxsForumMsgItem::loadParentMessage()"; std::cerr << std::endl; #endif + mLoadingParentMessage = true; RsThread::async([parent_msg,this]() { @@ -291,6 +310,8 @@ void GxsForumMsgItem::loadParentMessage(const RsGxsMessageId& parent_msg) mParentMessage = msg; fillParentMessage(); + mLoadingParentMessage = false; + }, this ); }); } @@ -480,6 +501,7 @@ void GxsForumMsgItem::setAsRead(bool doUpdate) } mCloseOnRead = false; + mLoadingSetAsRead = true; RsThread::async( [this, doUpdate]() { RsGxsGrpMsgIdPair msgPair = std::make_pair(groupId(), messageId()); @@ -489,6 +511,7 @@ void GxsForumMsgItem::setAsRead(bool doUpdate) if (doUpdate) { RsQThreadUtils::postToObject( [this]() { setReadStatus(false, true); + mLoadingSetAsRead = false; } ); } }); diff --git a/retroshare-gui/src/gui/feeds/GxsForumMsgItem.h b/retroshare-gui/src/gui/feeds/GxsForumMsgItem.h index 34166ee59..ec933d96e 100644 --- a/retroshare-gui/src/gui/feeds/GxsForumMsgItem.h +++ b/retroshare-gui/src/gui/feeds/GxsForumMsgItem.h @@ -87,6 +87,10 @@ private: private: bool mInFill; bool mCloseOnRead; + bool mLoadingMessage; + bool mLoadingParentMessage; + bool mLoadingGroup; + bool mLoadingSetAsRead; RsGxsForumGroup mGroup; RsGxsForumMsg mMessage;