fixing crash when deleting forum feed items while loading

This commit is contained in:
csoler 2023-08-03 20:22:30 +02:00
parent 5ca3b15188
commit 46e8db7d6d
3 changed files with 28 additions and 1 deletions

View File

@ -74,7 +74,7 @@ BasePostedItem::BasePostedItem( FeedHolder *feedHolder, uint32_t feedId
BasePostedItem::~BasePostedItem() 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) while( (mIsLoadingGroup || mIsLoadingMessage || mIsLoadingComment)
&& std::chrono::steady_clock::now() < timeout) && std::chrono::steady_clock::now() < timeout)
{ {

View File

@ -83,6 +83,19 @@ GxsForumMsgItem::GxsForumMsgItem(FeedHolder *feedHolder, uint32_t feedId, const
GxsForumMsgItem::~GxsForumMsgItem() 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); delete(ui);
} }
@ -167,6 +180,8 @@ QString GxsForumMsgItem::groupName()
void GxsForumMsgItem::loadGroup() void GxsForumMsgItem::loadGroup()
{ {
mLoadingGroup = true;
RsThread::async([this]() RsThread::async([this]()
{ {
// 1 - get group data // 1 - get group data
@ -199,6 +214,7 @@ void GxsForumMsgItem::loadGroup()
* after a blocking call to RetroShare API complete */ * after a blocking call to RetroShare API complete */
setGroup(group); setGroup(group);
mLoadingGroup = false;
}, this ); }, this );
}); });
@ -210,6 +226,7 @@ void GxsForumMsgItem::loadMessage()
std::cerr << "GxsForumMsgItem::loadMessage(): messageId=" << messageId() << " groupId=" << groupId() ; std::cerr << "GxsForumMsgItem::loadMessage(): messageId=" << messageId() << " groupId=" << groupId() ;
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
mLoadingMessage = true;
RsThread::async([this]() RsThread::async([this]()
{ {
@ -244,6 +261,7 @@ void GxsForumMsgItem::loadMessage()
* after a blocking call to RetroShare API complete */ * after a blocking call to RetroShare API complete */
setMessage(msg); setMessage(msg);
mLoadingMessage = false;
}, this ); }, this );
}); });
@ -255,6 +273,7 @@ void GxsForumMsgItem::loadParentMessage(const RsGxsMessageId& parent_msg)
std::cerr << "GxsForumMsgItem::loadParentMessage()"; std::cerr << "GxsForumMsgItem::loadParentMessage()";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
mLoadingParentMessage = true;
RsThread::async([parent_msg,this]() RsThread::async([parent_msg,this]()
{ {
@ -291,6 +310,8 @@ void GxsForumMsgItem::loadParentMessage(const RsGxsMessageId& parent_msg)
mParentMessage = msg; mParentMessage = msg;
fillParentMessage(); fillParentMessage();
mLoadingParentMessage = false;
}, this ); }, this );
}); });
} }
@ -480,6 +501,7 @@ void GxsForumMsgItem::setAsRead(bool doUpdate)
} }
mCloseOnRead = false; mCloseOnRead = false;
mLoadingSetAsRead = true;
RsThread::async( [this, doUpdate]() { RsThread::async( [this, doUpdate]() {
RsGxsGrpMsgIdPair msgPair = std::make_pair(groupId(), messageId()); RsGxsGrpMsgIdPair msgPair = std::make_pair(groupId(), messageId());
@ -489,6 +511,7 @@ void GxsForumMsgItem::setAsRead(bool doUpdate)
if (doUpdate) { if (doUpdate) {
RsQThreadUtils::postToObject( [this]() { RsQThreadUtils::postToObject( [this]() {
setReadStatus(false, true); setReadStatus(false, true);
mLoadingSetAsRead = false;
} ); } );
} }
}); });

View File

@ -87,6 +87,10 @@ private:
private: private:
bool mInFill; bool mInFill;
bool mCloseOnRead; bool mCloseOnRead;
bool mLoadingMessage;
bool mLoadingParentMessage;
bool mLoadingGroup;
bool mLoadingSetAsRead;
RsGxsForumGroup mGroup; RsGxsForumGroup mGroup;
RsGxsForumMsg mMessage; RsGxsForumMsg mMessage;