From 0bf11e45ea34a21b980c36c99be476613552d560 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Thu, 22 Oct 2020 22:07:00 +0300 Subject: SL-14150 Handle more cases of corrupted cache --- indra/newview/lltexturecache.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'indra/newview/lltexturecache.cpp') diff --git a/indra/newview/lltexturecache.cpp b/indra/newview/lltexturecache.cpp index 2e52414d71..649a994648 100644 --- a/indra/newview/lltexturecache.cpp +++ b/indra/newview/lltexturecache.cpp @@ -52,7 +52,8 @@ const S32 TEXTURE_CACHE_ENTRY_SIZE = FIRST_PACKET_SIZE;//1024; const F32 TEXTURE_CACHE_PURGE_AMOUNT = .20f; // % amount to reduce the cache by when it exceeds its limit const F32 TEXTURE_CACHE_LRU_SIZE = .10f; // % amount for LRU list (low overhead to regenerate) const S32 TEXTURE_FAST_CACHE_ENTRY_OVERHEAD = sizeof(S32) * 4; //w, h, c, level -const S32 TEXTURE_FAST_CACHE_ENTRY_SIZE = 16 * 16 * 4 + TEXTURE_FAST_CACHE_ENTRY_OVERHEAD; +const S32 TEXTURE_FAST_CACHE_DATA_SIZE = 16 * 16 * 4; +const S32 TEXTURE_FAST_CACHE_ENTRY_SIZE = TEXTURE_FAST_CACHE_DATA_SIZE + TEXTURE_FAST_CACHE_ENTRY_OVERHEAD; const F32 TEXTURE_LAZY_PURGE_TIME_LIMIT = .004f; // 4ms. Would be better to autoadjust, but there is a major cache rework in progress. class LLTextureCacheWorker : public LLWorkerClass @@ -2065,7 +2066,9 @@ LLPointer LLTextureCache::readFromFastCache(const LLUUID& id, S32& d } S32 image_size = head[0] * head[1] * head[2]; - if(!image_size) //invalid + if(image_size <= 0 + || image_size > TEXTURE_FAST_CACHE_DATA_SIZE + || head[3] < 0) //invalid { closeFastCache(); return NULL; @@ -2144,7 +2147,7 @@ bool LLTextureCache::writeToFastCache(LLUUID image_id, S32 id, LLPointer> i) * (h >> i) * c) > TEXTURE_FAST_CACHE_ENTRY_SIZE - TEXTURE_FAST_CACHE_ENTRY_OVERHEAD) + while(((w >> i) * (h >> i) * c) > TEXTURE_FAST_CACHE_DATA_SIZE) { ++i ; } -- cgit v1.2.3 From ac875d18768c88f6fb52cbbd0713d1fa9be7e534 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Fri, 23 Oct 2020 00:17:29 +0300 Subject: SL-14150 Comment for clarity and removed redundant check --- indra/newview/lltexturecache.cpp | 70 +++------------------------------------- 1 file changed, 4 insertions(+), 66 deletions(-) (limited to 'indra/newview/lltexturecache.cpp') diff --git a/indra/newview/lltexturecache.cpp b/indra/newview/lltexturecache.cpp index 649a994648..87e38a26af 100644 --- a/indra/newview/lltexturecache.cpp +++ b/indra/newview/lltexturecache.cpp @@ -2090,46 +2090,6 @@ LLPointer LLTextureCache::readFromFastCache(const LLUUID& id, S32& d return raw; } -#if LL_WINDOWS - -static const U32 STATUS_MSC_EXCEPTION = 0xE06D7363; // compiler specific - -U32 exception_dupe_filter(U32 code, struct _EXCEPTION_POINTERS *exception_infop) -{ - if (code == STATUS_MSC_EXCEPTION) - { - // C++ exception, go on - return EXCEPTION_CONTINUE_SEARCH; - } - else - { - // handle it - return EXCEPTION_EXECUTE_HANDLER; - } -} - -//due to unwinding -void dupe(LLPointer &raw) -{ - raw = raw->duplicate(); -} - -void logExceptionDupplicate(LLPointer &raw) -{ - __try - { - dupe(raw); - } - __except (exception_dupe_filter(GetExceptionCode(), GetExceptionInformation())) - { - // convert to C++ styled exception - char integer_string[32]; - sprintf(integer_string, "SEH, code: %lu\n", GetExceptionCode()); - throw std::exception(integer_string); - } -} -#endif - //return the fast cache location bool LLTextureCache::writeToFastCache(LLUUID image_id, S32 id, LLPointer raw, S32 discardlevel) { @@ -2146,7 +2106,8 @@ bool LLTextureCache::writeToFastCache(LLUUID image_id, S32 id, LLPointergetComponents(); S32 i = 0 ; - + + // Search for a discard level that will fit into fast cache while(((w >> i) * (h >> i) * c) > TEXTURE_FAST_CACHE_DATA_SIZE) { ++i ; @@ -2158,31 +2119,8 @@ bool LLTextureCache::writeToFastCache(LLUUID image_id, S32 id, LLPointer>= i; if(w * h *c > 0) //valid { - //make a duplicate to keep the original raw image untouched. - - try - { -#if LL_WINDOWS - // Temporary diagnostics for scale/duplicate crash - logExceptionDupplicate(raw); -#else - raw = raw->duplicate(); -#endif - } - catch (...) - { - removeFromCache(image_id); - LL_ERRS() << "Failed to cache image: " << image_id - << " local id: " << id - << " Exception: " << boost::current_exception_diagnostic_information() - << " Image new width: " << w - << " Image new height: " << h - << " Image new components: " << c - << " Image discard difference: " << i - << LL_ENDL; - - return false; - } + // make a duplicate to keep the original raw image untouched. + raw = raw->duplicate(); if (raw->isBufferInvalid()) { -- cgit v1.2.3 From d07dea27ab1bc2457f8bd2ab24d8cdbfcb0e9e3c Mon Sep 17 00:00:00 2001 From: Andrey Lihatskiy Date: Wed, 11 Nov 2020 22:41:32 +0200 Subject: Post-merge leftover cleanup; buildfix --- indra/newview/lltexturecache.cpp | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) (limited to 'indra/newview/lltexturecache.cpp') diff --git a/indra/newview/lltexturecache.cpp b/indra/newview/lltexturecache.cpp index d0e313bfdb..a9f19dc32d 100644 --- a/indra/newview/lltexturecache.cpp +++ b/indra/newview/lltexturecache.cpp @@ -2123,30 +2123,7 @@ bool LLTextureCache::writeToFastCache(LLUUID image_id, S32 id, LLPointer 0) //valid { // Make a duplicate to keep the original raw image untouched. - // Might be good idea to do a copy during writeToCache() call instead of here - try - { -#if LL_WINDOWS - // Temporary diagnostics for scale/duplicate crash - logExceptionDupplicate(raw); -#else - raw = raw->duplicate(); -#endif - } - catch (...) - { - removeFromCache(image_id); - LL_ERRS() << "Failed to cache image: " << image_id - << " local id: " << id - << " Exception: " << boost::current_exception_diagnostic_information() - << " Image new width: " << w - << " Image new height: " << h - << " Image new components: " << c - << " Image discard difference: " << i - << LL_ENDL; - - return false; - } + raw = raw->duplicate(); if (raw->isBufferInvalid()) { -- cgit v1.2.3