aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-10-18 06:48:09 +0200
committerdec05eba <dec05eba@protonmail.com>2020-10-18 06:48:09 +0200
commit7e1a950a0be2871045e0dda6ba2adc892d323464 (patch)
tree90190f3a987ffb1b0fc6d9eaa499766155bb4d32
parentfa4897265ae955872b0c2530300a3110e995510e (diff)
Fix potential crash in thumbnail loader
-rw-r--r--TODO3
-rw-r--r--include/AsyncImageLoader.hpp1
-rw-r--r--src/AsyncImageLoader.cpp6
-rw-r--r--src/QuickMedia.cpp2
4 files changed, 10 insertions, 2 deletions
diff --git a/TODO b/TODO
index 869062c..edd4525 100644
--- a/TODO
+++ b/TODO
@@ -110,4 +110,5 @@ Fix inconsistent behavior when editing a message that is replied to in matrix. R
to fix this we could perhaps replace the newly created body items for replies when loading old messages and one of the old messages is also one of the embedded messages (by event id).
Add button to skip to next video. MPV has this feature when setting "next" video (can be done over IPC).
Handle room leave in matrix and remove rooms from the list.
-Use a custom allocator that replaces malloc/realloc/free/new/delete to release memory properly, using munmap in free/delete. The C allocator doesn't do that! memory usage remains high after one large allocation. The C allocator only marks it as free. \ No newline at end of file
+Use a custom allocator that replaces malloc/realloc/free/new/delete to release memory properly, using munmap in free/delete. The C allocator doesn't do that! memory usage remains high after one large allocation. The C allocator only marks it as free.
+Ignore timestamp ordering for messages in matrix? element seems to do that, and also we need the latest message to be last i guess to set read markers properly? \ No newline at end of file
diff --git a/include/AsyncImageLoader.hpp b/include/AsyncImageLoader.hpp
index 27e46e3..fe8d52a 100644
--- a/include/AsyncImageLoader.hpp
+++ b/include/AsyncImageLoader.hpp
@@ -23,6 +23,7 @@ namespace QuickMedia {
class AsyncImageLoader {
public:
+ ~AsyncImageLoader();
// Returns false if the image loader is already loading an image. In that case, this function should be called again later.
// set |resize_target_size| to {0, 0} to disable resizing.
// |thumbnail_data.loading_state| has to be LoadingState::NOT_LOADED when calling this!
diff --git a/src/AsyncImageLoader.cpp b/src/AsyncImageLoader.cpp
index bfef294..fb864c2 100644
--- a/src/AsyncImageLoader.cpp
+++ b/src/AsyncImageLoader.cpp
@@ -70,6 +70,12 @@ namespace QuickMedia {
return "";
}
+ // TODO: Remove and use std::thread and detach instead of std::async
+ AsyncImageLoader::~AsyncImageLoader() {
+ if(load_image_future.valid())
+ load_image_future.get();
+ }
+
// TODO: Run in 5 different threads, and add download_to_file(_cache) to reduce memory usage in each (use -O curl option)
bool AsyncImageLoader::load_thumbnail(const std::string &url, bool local, sf::Vector2i resize_target_size, bool use_tor, std::shared_ptr<ThumbnailData> thumbnail_data) {
update();
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 10224e2..13f7db9 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -3744,7 +3744,7 @@ namespace QuickMedia {
async_image_loader.update();
if(current_room_body_data && room_avatar_thumbnail_data->loading_state == LoadingState::NOT_LOADED)
- async_image_loader.load_thumbnail(current_room_body_data->body_item->thumbnail_url, false, sf::Vector2i(), use_tor, room_avatar_thumbnail_data);
+ async_image_loader.load_thumbnail(current_room_body_data->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))