try to fix crash when linphone chatroom send a signal and ChatCore is already destroyed

This commit is contained in:
Gaelle Braud 2026-01-22 15:58:12 +01:00
parent bc8f542896
commit 41b2086b66
4 changed files with 10 additions and 9 deletions

View file

@ -43,7 +43,7 @@ QSharedPointer<ChatCore> ChatCore::create(const std::shared_ptr<linphone::ChatRo
} }
ChatCore::ChatCore(const std::shared_ptr<linphone::ChatRoom> &chatRoom) : QObject(nullptr) { ChatCore::ChatCore(const std::shared_ptr<linphone::ChatRoom> &chatRoom) : QObject(nullptr) {
// lDebug() << "[ChatCore] new" << this; lDebug() << "[ChatCore] new" << this;
mustBeInLinphoneThread(getClassName()); mustBeInLinphoneThread(getClassName());
App::getInstance()->mEngine->setObjectOwnership(this, QQmlEngine::CppOwnership); App::getInstance()->mEngine->setObjectOwnership(this, QQmlEngine::CppOwnership);
mLastUpdatedTime = QDateTime::fromSecsSinceEpoch(chatRoom->getLastUpdateTime()); mLastUpdatedTime = QDateTime::fromSecsSinceEpoch(chatRoom->getLastUpdateTime());
@ -211,7 +211,7 @@ void ChatCore::setSelf(QSharedPointer<ChatCore> me) {
const std::shared_ptr<const linphone::EventLog> &eventLog) { const std::shared_ptr<const linphone::EventLog> &eventLog) {
if (mChatModel->getMonitor() != chatRoom) return; if (mChatModel->getMonitor() != chatRoom) return;
if (!eventLog) return; if (!eventLog) return;
lDebug() << "EVENT LOG RECEIVED IN CHATROOM" << mChatModel->getTitle(); lDebug() << log().arg("EVENT LOG RECEIVED IN CHATROOM") << this << mChatModel->getTitle();
auto event = EventLogCore::create(eventLog, chatRoom); auto event = EventLogCore::create(eventLog, chatRoom);
if (event->isHandled()) { if (event->isHandled()) {
mChatModelConnection->invokeToCore([this, event]() { emit eventsInserted({event}); }); mChatModelConnection->invokeToCore([this, event]() { emit eventsInserted({event}); });
@ -224,7 +224,7 @@ void ChatCore::setSelf(QSharedPointer<ChatCore> me) {
&ChatModel::chatMessagesReceived, [this](const std::shared_ptr<linphone::ChatRoom> &chatRoom, &ChatModel::chatMessagesReceived, [this](const std::shared_ptr<linphone::ChatRoom> &chatRoom,
const std::list<std::shared_ptr<linphone::EventLog>> &eventsLog) { const std::list<std::shared_ptr<linphone::EventLog>> &eventsLog) {
if (mChatModel->getMonitor() != chatRoom) return; if (mChatModel->getMonitor() != chatRoom) return;
lDebug() << "CHAT MESSAGE RECEIVED IN CHATROOM" << mChatModel->getTitle(); lDebug() << log().arg("CHAT MESSAGE RECEIVED IN CHATROOM") << this << mChatModel->getTitle();
QList<QSharedPointer<EventLogCore>> list; QList<QSharedPointer<EventLogCore>> list;
for (auto &e : eventsLog) { for (auto &e : eventsLog) {
auto event = EventLogCore::create(e, chatRoom); auto event = EventLogCore::create(e, chatRoom);

View file

@ -130,6 +130,7 @@ void ChatList::setSelf(QSharedPointer<ChatList> me) {
} }
endResetModel(); endResetModel();
setIsUpdating(false); setIsUpdating(false);
chats->clear();
delete chats; delete chats;
}); });
}); });

View file

@ -1592,7 +1592,7 @@ VariantObject *Utils::getCurrentCallChat(CallGui *call) {
auto linphoneChatRoom = ToolModel::lookupCurrentCallChat(callModel); auto linphoneChatRoom = ToolModel::lookupCurrentCallChat(callModel);
if (linphoneChatRoom) { if (linphoneChatRoom) {
auto chatCore = ChatCore::create(linphoneChatRoom); auto chatCore = ChatCore::create(linphoneChatRoom);
return QVariant::fromValue(new ChatGui(chatCore)); return chatCore ? QVariant::fromValue(new ChatGui(chatCore)) : QVariant();
} else { } else {
// Only try to create chatroom if 1-1 call // Only try to create chatroom if 1-1 call
if (!callModel->getConference()) { if (!callModel->getConference()) {
@ -1603,7 +1603,7 @@ VariantObject *Utils::getCurrentCallChat(CallGui *call) {
lInfo() << "[Utils] Chatroom created with" << callModel->getRemoteAddress()->asStringUriOnly(); lInfo() << "[Utils] Chatroom created with" << callModel->getRemoteAddress()->asStringUriOnly();
auto id = linphoneChatRoom->getIdentifier(); auto id = linphoneChatRoom->getIdentifier();
auto chatCore = ChatCore::create(linphoneChatRoom); auto chatCore = ChatCore::create(linphoneChatRoom);
return QVariant::fromValue(new ChatGui(chatCore)); return chatCore ? QVariant::fromValue(new ChatGui(chatCore)) : QVariant();
} else { } else {
lWarning() << "[Utils] Failed to create 1-1 conversation with" lWarning() << "[Utils] Failed to create 1-1 conversation with"
<< callModel->getRemoteAddress()->asStringUriOnly() << "!"; << callModel->getRemoteAddress()->asStringUriOnly() << "!";
@ -1625,14 +1625,14 @@ VariantObject *Utils::getChatForAddress(QString address) {
auto linphoneChatRoom = ToolModel::lookupChatForAddress(linAddr); auto linphoneChatRoom = ToolModel::lookupChatForAddress(linAddr);
if (linphoneChatRoom) { if (linphoneChatRoom) {
auto chatCore = ChatCore::create(linphoneChatRoom); auto chatCore = ChatCore::create(linphoneChatRoom);
return QVariant::fromValue(new ChatGui(chatCore)); return chatCore ? QVariant::fromValue(new ChatGui(chatCore)) : QVariant();
} else { } else {
lInfo() << "[Utils] Did not find existing chat room, create one"; lInfo() << "[Utils] Did not find existing chat room, create one";
linphoneChatRoom = ToolModel::createChatForAddress(linAddr); linphoneChatRoom = ToolModel::createChatForAddress(linAddr);
if (linphoneChatRoom != nullptr) { if (linphoneChatRoom != nullptr) {
lInfo() << "[Utils] Chatroom created with" << linAddr->asStringUriOnly(); lInfo() << "[Utils] Chatroom created with" << linAddr->asStringUriOnly();
auto chatCore = ChatCore::create(linphoneChatRoom); auto chatCore = ChatCore::create(linphoneChatRoom);
return QVariant::fromValue(new ChatGui(chatCore)); return chatCore ? QVariant::fromValue(new ChatGui(chatCore)) : QVariant();
} else { } else {
lWarning() << "[Utils] Failed to create 1-1 conversation with" << linAddr->asStringUriOnly() << "!"; lWarning() << "[Utils] Failed to create 1-1 conversation with" << linAddr->asStringUriOnly() << "!";
//: Failed to create 1-1 conversation with %1 ! //: Failed to create 1-1 conversation with %1 !
@ -1662,7 +1662,7 @@ VariantObject *Utils::createGroupChat(QString subject, QStringList participantAd
auto linphoneChatRoom = ToolModel::createGroupChatRoom(subject, addresses); auto linphoneChatRoom = ToolModel::createGroupChatRoom(subject, addresses);
if (linphoneChatRoom) { if (linphoneChatRoom) {
auto chatCore = ChatCore::create(linphoneChatRoom); auto chatCore = ChatCore::create(linphoneChatRoom);
return QVariant::fromValue(new ChatGui(chatCore)); return chatCore ? QVariant::fromValue(new ChatGui(chatCore)) : QVariant();
} else { } else {
return QVariant(); return QVariant();
} }

View file

@ -60,7 +60,7 @@ ListView {
} }
} }
onChatAdded: (chat) => { onChatAdded: (chat) => {
mainItem.chatToSelect = chat // mainItem.chatToSelect = chat
} }
onRowsRemoved: { onRowsRemoved: {
var index = mainItem.currentIndex var index = mainItem.currentIndex