aboutsummaryrefslogtreecommitdiff
path: root/src/Cache.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-04-21 04:17:24 +0200
committerdec05eba <dec05eba@protonmail.com>2018-04-21 04:17:29 +0200
commit424b02609fa34175a4e2aadb95e68b3c9c8dc93c (patch)
treec6312f04ea70a483fec9e76dcef8ae3ffa5e6424 /src/Cache.cpp
parent09a8ade6becca2a71f45ff0db5f4bf6d64afb212 (diff)
Fix emoji async download drawing
Diffstat (limited to 'src/Cache.cpp')
-rw-r--r--src/Cache.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/Cache.cpp b/src/Cache.cpp
index 7e3272a..ba57d4c 100644
--- a/src/Cache.cpp
+++ b/src/Cache.cpp
@@ -71,6 +71,7 @@ namespace dchat
if(it->process->try_get_exit_status(exitStatus))
{
bool failed = exitStatus != 0;
+ ImageByUrlResult &imageByUrlResult = imageUrlCache[it->url];
if(!failed)
{
@@ -80,10 +81,10 @@ namespace dchat
try
{
- const sf::Texture *texture = ResourceCache::getTexture(filepath.string());
- ImageByUrlResult &imageByUrlResult = imageUrlCache[it->url];
+ sf::Texture *texture = ResourceCache::getTexture(filepath.string());
imageByUrlResult.texture = texture;
imageByUrlResult.type = ImageByUrlResult::Type::CACHED;
+ printf("Image downloaded from url: %s, texture: %u\n", it->url.c_str(), texture);
}
catch(FailedToLoadResourceException &e)
{
@@ -94,7 +95,7 @@ namespace dchat
if(failed)
{
- imageUrlCache[it->url].type = ImageByUrlResult::Type::FAILED_DOWNLOAD;
+ imageByUrlResult.type = ImageByUrlResult::Type::FAILED_DOWNLOAD;
fprintf(stderr, "Image download failed for url: %s\n", it->url.c_str());
}
@@ -107,6 +108,8 @@ namespace dchat
while(imageDownloadProcesses.empty())
this_thread::sleep_for(chrono::milliseconds(20));
+
+ this_thread::sleep_for(chrono::milliseconds(20));
}
});
downloadWaitThread.detach();
@@ -114,6 +117,7 @@ namespace dchat
const ImageByUrlResult Cache::getImageByUrl(const string &url, int downloadLimitBytes)
{
+ lock_guard<mutex> lock(imageDownloadMutex);
auto it = imageUrlCache.find(url);
if(it != imageUrlCache.end())
return it->second;
@@ -128,10 +132,10 @@ namespace dchat
{
try
{
- const sf::Texture *texture = ResourceCache::getTexture(filepath.string());
- lock_guard<mutex> lock(imageDownloadMutex);
+ sf::Texture *texture = ResourceCache::getTexture(filepath.string());
ImageByUrlResult result { texture, ImageByUrlResult::Type::CACHED };
imageUrlCache[url] = result;
+ printf("Loading image from file cache: %s\n", url.c_str());
return result;
}
catch(FailedToLoadResourceException &e)
@@ -140,7 +144,6 @@ namespace dchat
}
}
- lock_guard<mutex> lock(imageDownloadMutex);
ImageByUrlResult result { nullptr, ImageByUrlResult::Type::DOWNLOADING };
imageUrlCache[url] = result;