From bab9abf4af10919a2a432dc73fec27f6ef89948d Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Thu, 11 Feb 2021 18:03:16 -0500 Subject: speed up images with libcurl multi, raise concurrency also maybe fix some rare crash --- imgmanager.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'imgmanager.cpp') diff --git a/imgmanager.cpp b/imgmanager.cpp index 8d23144..261b8d6 100644 --- a/imgmanager.cpp +++ b/imgmanager.cpp @@ -45,10 +45,14 @@ void ImageManager::LoadFromURL(std::string url, callback_type cb) { m_cache.GetFileFromURL(url, [this, url, signal](std::string path) { try { auto buf = ReadFileToPixbuf(path); - m_cb_mutex.lock(); - m_cb_queue.push([signal, buf]() { signal.emit(buf); }); - m_cb_dispatcher.emit(); - m_cb_mutex.unlock(); + if (!buf) + printf("%s (%s) is null\n", url.c_str(), path.c_str()); + else { + m_cb_mutex.lock(); + m_cb_queue.push([signal, buf]() { signal.emit(buf); }); + m_cb_dispatcher.emit(); + m_cb_mutex.unlock(); + } } catch (const std::exception &e) { fprintf(stderr, "err loading pixbuf from %s: %s\n", path.c_str(), e.what()); } @@ -61,10 +65,14 @@ void ImageManager::LoadAnimationFromURL(std::string url, int w, int h, callback_ m_cache.GetFileFromURL(url, [this, url, signal, w, h](std::string path) { try { auto buf = ReadFileToPixbufAnimation(path, w, h); - m_cb_mutex.lock(); - m_cb_queue.push([signal, buf]() { signal.emit(buf); }); - m_cb_dispatcher.emit(); - m_cb_mutex.unlock(); + if (!buf) + printf("%s (%s) is null\n", url.c_str(), path.c_str()); + else { + m_cb_mutex.lock(); + m_cb_queue.push([signal, buf]() { signal.emit(buf); }); + m_cb_dispatcher.emit(); + m_cb_mutex.unlock(); + } } catch (const std::exception &e) { fprintf(stderr, "err loading pixbuf animation from %s: %s\n", path.c_str(), e.what()); } -- cgit v1.2.3