From 803eb1d3814e469b811f3b60b5df35d8197b71f6 Mon Sep 17 00:00:00 2001 From: Sergey Lipskiy Date: Sat, 2 Jul 2016 23:20:41 +0600 Subject: [PATCH] Clear cache if its size is too large. --- src/Textures.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Textures.cpp b/src/Textures.cpp index 03326e74..7b2c3a35 100644 --- a/src/Textures.cpp +++ b/src/Textures.cpp @@ -524,14 +524,15 @@ void TextureCache::destroy() void TextureCache::_checkCacheSize() { #ifdef VC - if (m_textures.size() > 15000) { - CachedTexture& piTex = m_textures.back(); - m_cachedBytes -= piTex.textureBytes; - glDeleteTextures(1, &piTex.glName); - m_lruTextureLocations.erase(piTex.crc); - m_textures.pop_back(); - } + const size_t maxCacheSize = 15000; +#else + const size_t maxCacheSize = 128000; #endif + // Clear cache if its size is too large. + if (m_textures.size() >= maxCacheSize) { + _clear(); + return; + } if (m_cachedBytes <= m_maxBytes) return;