aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-02-05 05:18:31 +0100
committerdec05eba <dec05eba@protonmail.com>2021-02-05 05:18:31 +0100
commit0d4b8bacce933e34a41769b1051b25f82f922201 (patch)
treeef1894ccfd66c41351568937182f16abb6c754f4 /src/plugins
parent1591c329889b0cd6eb3d579e60eeaf93df131a71 (diff)
Matrix: fix crash when a room is being removed in one thread and the room description is set in another, at the same time
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/Matrix.cpp16
1 files changed, 8 insertions, 8 deletions
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<BodyItem*>(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<std::mutex> lock(mutex);
#if 1
- BodyItem *room_body_item = static_cast<BodyItem*>(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<BodyItem> body_item = body->items[room_body_index];
int body_swap_index = -1;