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/QuickMedia.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/QuickMedia.cpp') diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 719345d..76bd084 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -3440,7 +3440,7 @@ namespace QuickMedia { process_pinned_events(std::move(pinned_events)); tabs[PINNED_TAB_INDEX].body->select_last_item(); - room_name_text.setString(static_cast(current_room->userdata)->get_title()); + room_name_text.setString(current_room->body_item->get_title()); room_avatar_thumbnail_data = std::make_shared(); read_marker_timeout_ms = 0; @@ -4429,8 +4429,8 @@ namespace QuickMedia { typing_state_queue.push(false); } - if(current_room && current_room->userdata && room_avatar_thumbnail_data->loading_state == LoadingState::NOT_LOADED) - AsyncImageLoader::get_instance().load_thumbnail(static_cast(current_room->userdata)->thumbnail_url, false, sf::Vector2i(32, 32), use_tor, room_avatar_thumbnail_data); + if(current_room && current_room->body_item && room_avatar_thumbnail_data->loading_state == LoadingState::NOT_LOADED) + AsyncImageLoader::get_instance().load_thumbnail(current_room->body_item->thumbnail_url, false, sf::Vector2i(32, 32), use_tor, room_avatar_thumbnail_data); if(room_avatar_thumbnail_data->loading_state == LoadingState::FINISHED_LOADING && room_avatar_thumbnail_data->image->getSize().x > 0 && room_avatar_thumbnail_data->image->getSize().y > 0) { if(!room_avatar_thumbnail_data->texture.loadFromImage(*room_avatar_thumbnail_data->image)) @@ -4686,10 +4686,9 @@ namespace QuickMedia { tabs[MESSAGES_TAB_INDEX].body->draw_item(window, currently_operating_on_item.get(), body_item_pos, body_item_size); } - if(selected_tab == MESSAGES_TAB_INDEX && current_room && current_room->userdata && !current_room->last_message_read) { + if(selected_tab == MESSAGES_TAB_INDEX && current_room && current_room->body_item && !current_room->last_message_read) { if(tabs[selected_tab].body->is_last_item_fully_visible()) { - BodyItem *current_room_body_item = static_cast(current_room->userdata); - std::string room_desc = current_room_body_item->get_description(); + std::string room_desc = current_room->body_item->get_description(); if(strncmp(room_desc.c_str(), "Unread: ", 8) == 0) room_desc = room_desc.substr(8); size_t last_line_start = room_desc.rfind('\n'); @@ -4699,9 +4698,9 @@ namespace QuickMedia { if(last_line_size >= 23 && memcmp(&room_desc[last_line_start], "** ", 3) == 0 && memcmp(&room_desc[room_desc.size() - 20], "unread mention(s) **", 20) == 0) room_desc.erase(room_desc.begin() + last_line_start - 1, room_desc.end()); } - current_room_body_item->set_description(std::move(room_desc)); + current_room->body_item->set_description(std::move(room_desc)); // TODO: Show a line like nheko instead for unread messages, or something else - current_room_body_item->set_title_color(sf::Color::White); + current_room->body_item->set_title_color(sf::Color::White); current_room->last_message_read = true; // TODO: Maybe set this instead when the mention is visible on the screen? current_room->unread_notification_count = 0; -- cgit v1.2.3