From dee064a7587b1bc5504e2e79cec1c02f7b5fc898 Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Mon, 15 May 2023 20:57:19 +0200 Subject: [PATCH] Fix crash in room switching --- src/chatdocumenthandler.h | 2 +- src/roommanager.cpp | 10 +++++++--- src/roommanager.h | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/chatdocumenthandler.h b/src/chatdocumenthandler.h index 76136ca4d..89807f521 100644 --- a/src/chatdocumenthandler.h +++ b/src/chatdocumenthandler.h @@ -159,7 +159,7 @@ private: bool m_isEdit = false; - QQuickTextDocument *m_document; + QPointer m_document; QPointer m_room; bool completionVisible = false; diff --git a/src/roommanager.cpp b/src/roommanager.cpp index 852ca6feb..cb8d6d0be 100644 --- a/src/roommanager.cpp +++ b/src/roommanager.cpp @@ -131,9 +131,13 @@ void RoomManager::enterRoom(NeoChatRoom *room) } if (m_currentRoom && m_chatDocumentHandler) { // We're doing these things here because it is critical that they are switched at the same time - m_currentRoom->setSavedText(m_chatDocumentHandler->document()->textDocument()->toPlainText()); - m_chatDocumentHandler->setRoom(room); - m_chatDocumentHandler->document()->textDocument()->setPlainText(room->savedText()); + if (m_chatDocumentHandler->document()) { + m_currentRoom->setSavedText(m_chatDocumentHandler->document()->textDocument()->toPlainText()); + m_chatDocumentHandler->setRoom(room); + m_chatDocumentHandler->document()->textDocument()->setPlainText(room->savedText()); + } else { + m_chatDocumentHandler->setRoom(room); + } } m_lastCurrentRoom = std::exchange(m_currentRoom, room); Q_EMIT currentRoomChanged(); diff --git a/src/roommanager.h b/src/roommanager.h index 535202bbe..54b4106bb 100644 --- a/src/roommanager.h +++ b/src/roommanager.h @@ -234,5 +234,5 @@ private: QString m_arg; KConfig m_config; KConfigGroup m_lastRoomConfig; - ChatDocumentHandler *m_chatDocumentHandler; + QPointer m_chatDocumentHandler; };