aboutsummaryrefslogtreecommitdiff
path: root/src/Cache.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-04-29 08:17:30 +0200
committerdec05eba <dec05eba@protonmail.com>2018-04-29 08:17:36 +0200
commitf90a5705bd65a4ebb5edc9df003a383039fec555 (patch)
treef0180d946bddc15a0a13d9148562418cb3a4108e /src/Cache.cpp
parent68dcd3c4e17355e1c2b640fe1382743d7cb61ea2 (diff)
Change design, fix crash when closing application
Diffstat (limited to 'src/Cache.cpp')
-rw-r--r--src/Cache.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/Cache.cpp b/src/Cache.cpp
index bfa3df4..d402d36 100644
--- a/src/Cache.cpp
+++ b/src/Cache.cpp
@@ -95,11 +95,12 @@ namespace dchat
return { (sf::Texture*)nullptr, ImageByUrlResult::Type::FAILED_DOWNLOAD };
}
- Cache::Cache()
+ Cache::Cache() :
+ alive(true)
{
downloadWaitThread = thread([this]
{
- while(true)
+ while(alive)
{
for(vector<ImageDownloadInfo>::iterator it = imageDownloadProcesses.begin(); it != imageDownloadProcesses.end();)
{
@@ -133,7 +134,7 @@ namespace dchat
++it;
}
- while(imageDownloadProcesses.empty() && imageDownloadProcessesQueue.empty())
+ while(alive && imageDownloadProcesses.empty() && imageDownloadProcessesQueue.empty())
this_thread::sleep_for(chrono::milliseconds(20));
if(!imageDownloadProcessesQueue.empty())
@@ -150,7 +151,12 @@ namespace dchat
this_thread::sleep_for(chrono::milliseconds(20));
}
});
- downloadWaitThread.detach();
+ }
+
+ Cache::~Cache()
+ {
+ alive = false;
+ downloadWaitThread.join();
}
const ImageByUrlResult Cache::getImageByUrl(const string &url, int downloadLimitBytes)