forked from townforge/townforge
game: guard against the terrain cache directory being removed at runtime
This commit is contained in:
parent
2047ebc400
commit
bfd46e0a06
@ -75,6 +75,9 @@ static void prune_terrain_files(size_t max_size)
|
||||
|
||||
uint64_t GetCurrentTerrainCacheUsage()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
boost::system::error_code ec;
|
||||
const boost::filesystem::directory_iterator end_itr;
|
||||
const boost::filesystem::path parent_path = cache_dir;
|
||||
@ -90,6 +93,9 @@ uint64_t GetCurrentTerrainCacheUsage()
|
||||
total_size += statbuf.st_size;
|
||||
}
|
||||
return total_size;
|
||||
|
||||
}
|
||||
catch(const std::exception &e) { return 0; }
|
||||
}
|
||||
|
||||
void SetTerrainCacheDirectory(const std::string &dir)
|
||||
@ -99,7 +105,8 @@ void SetTerrainCacheDirectory(const std::string &dir)
|
||||
|
||||
void ClearTerrainCache()
|
||||
{
|
||||
prune_terrain_files(0);
|
||||
try { prune_terrain_files(0); }
|
||||
catch(...) {}
|
||||
}
|
||||
|
||||
static boost::shared_ptr<int16_t[]> encode_deltas(const boost::shared_ptr<uint16_t[]> &data, size_t tiles)
|
||||
@ -122,7 +129,8 @@ void SetCachedTerrain(const std::string &tag, const boost::shared_ptr<uint16_t[]
|
||||
boost::thread([data, filename, tiles]()
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
prune_terrain_files(terrain_cache_size);
|
||||
try { prune_terrain_files(terrain_cache_size); }
|
||||
catch(...) {}
|
||||
const boost::shared_ptr<int16_t[]> deltas(encode_deltas(data, tiles));
|
||||
const unsigned max_bytes = Urho3D::EstimateCompressBound(tiles * 2);
|
||||
std::unique_ptr<uint8_t[]> buf(new uint8_t[max_bytes]);
|
||||
|
Loading…
Reference in New Issue
Block a user