From 0d4b8bacce933e34a41769b1051b25f82f922201 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 5 Feb 2021 05:18:31 +0100 Subject: Matrix: fix crash when a room is being removed in one thread and the room description is set in another, at the same time --- src/plugins/Matrix.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/plugins/Matrix.cpp') diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index ba8533b..3a2c02c 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -296,6 +296,8 @@ namespace QuickMedia { //message_by_event_id.clear(); pinned_events.clear(); tags.clear(); + // TODO: Do this? what if its being used in another thread? + //body_item.reset(); } MatrixQuickMedia::MatrixQuickMedia(Program *program, Matrix *matrix, MatrixRoomsPage *rooms_page, MatrixRoomTagsPage *room_tags_page, MatrixInvitesPage *invites_page) : @@ -317,7 +319,7 @@ namespace QuickMedia { body_item->userdata = room; // Note: this has to be valid as long as the room list is valid! body_item->thumbnail_mask_type = ThumbnailMaskType::CIRCLE; body_item->thumbnail_size = sf::Vector2i(32, 32); - room->userdata = body_item.get(); + room->body_item = body_item; rooms_page->add_body_item(body_item); room_body_item_by_room[room] = body_item; } @@ -484,9 +486,8 @@ namespace QuickMedia { if(last_new_message->timestamp > read_marker_message_timestamp) last_unread_message = last_new_message.get(); - BodyItem *room_body_item = static_cast(room->userdata); //assert(room_body_item); - if(!room_body_item) + if(!room->body_item) return; if(last_unread_message && !sync_is_cache) { @@ -494,14 +495,14 @@ namespace QuickMedia { int unread_notification_count = room->unread_notification_count; if(unread_notification_count > 0) room_desc += "\n** " + std::to_string(unread_notification_count) + " unread mention(s) **"; // TODO: Better notification? - room_body_item->set_description(std::move(room_desc)); - room_body_item->set_title_color(sf::Color(255, 100, 100)); + room->body_item->set_description(std::move(room_desc)); + room->body_item->set_title_color(sf::Color(255, 100, 100)); room->last_message_read = false; rooms_page->move_room_to_top(room); room_tags_page->move_room_to_top(room); } else if(is_initial_sync) { - room_body_item->set_description(matrix->message_get_author_displayname(last_new_message.get()) + ": " + message_to_room_description_text(last_new_message.get())); + room->body_item->set_description(matrix->message_get_author_displayname(last_new_message.get()) + ": " + message_to_room_description_text(last_new_message.get())); } } @@ -608,8 +609,7 @@ namespace QuickMedia { // TODO: Optimize with hash map instead of linear search? or cache the index std::lock_guard lock(mutex); #if 1 - BodyItem *room_body_item = static_cast(room->userdata); - int room_body_index = body->get_index_by_body_item(room_body_item); + int room_body_index = body->get_index_by_body_item(room->body_item.get()); if(room_body_index != -1) { std::shared_ptr body_item = body->items[room_body_index]; int body_swap_index = -1; -- cgit v1.2.3