Fixed fast cache read creating invalid textures (1024x1024+ sized)

When saving textures to the fast cache, which only supports 16x16 textures at 4 bytes per pixel, the system will force scale down textures to fit, even beyond the allowed MAX_DISCARD_LEVEL, such as 1024x1024 having Discard = 6 and 2048x2048 texture having Discard = 7 and writing it to the headers.

Updated the readFromFastCache to expand invalid textures to be at the MAX_DISCARD_LEVEL(5) discard instead of at 6, 7 or 8. Scale up the 16x16 textures to match the requirements for the textures at MAX_DISCARD_LEVEL.

Mostly for re-loading after high bias scenario as these can cause crashes in the KDU decoder codebase. Which can possibly lead to deadlocked threads as well as bad textures clogging up the fetch system.

Example Firestorm.log output of the error in action.

2025-02-21T13:47:43Z INFO   LLKDUMessage::put_text : KDU Error: Attempting to access a non-existent resolution level within some tile-component.  Problem almost certainly caused by trying to discard more resolution levels than the number of DWT levels used to compress a tile-component.
Exception thrown at 0x00007FFA77A1BB0A in firestorm-bin.exe: Microsoft C++ exception: boost::wrapexcept<`anonymous namespace'::KDUError> at memory location 0x000000C3985FF470.
2025-02-21T13:47:43Z WARNING   LLTextureFetchWorker::callbackDecoded : DECODE FAILED: 0c699ab7-dd72-bfc9-d695-267e1a3f936a Discard: 6, reason: LLKDUMessageError::flush()
2025-02-21T13:47:43Z WARNING   _ll_apr_warn_status : APR: firestorm\phoenix-firestorm-foreverfps\indra\llcommon\llapr.cpp:651 The system cannot find the file specified.
2025-02-21T13:47:43Z WARNING   LLAPRFile::remove :  Attempting to remove filename: AppData\Local\FirestormOS_x64\texturecache\0\0c699ab7-dd72-bfc9-d695-267e1a3f936a.texture
2025-02-21T13:47:43Z INFO   LLKDUMessage::put_text : KDU Error: Kakadu Core Error:
master
minerjr 2025-02-21 12:01:54 -04:00
parent 8a527d676e
commit c121c12f77
1 changed files with 22 additions and 0 deletions

View File

@ -2082,6 +2082,28 @@ LLPointer<LLImageRaw> LLTextureCache::readFromFastCache(const LLUUID& id, S32& d
}
LLPointer<LLImageRaw> raw = new LLImageRaw(data, head[0], head[1], head[2], true);
// <FS:minerjr>
// This fixes the invalid discard values from being created which cause the decoder code to fail when trying to handle 6 and 7's which are above the MAX_DISCARD_LEVEL of 5
// especially on load
// We will expand the 16x16 texture to the actual MAX_DISCARD_LEVEL texture size, it may be blurry until the user gets closer but 5 discard value should be objects far from the camera.
// So a 1024x1024 texture with a dicard of 6 will become 32x32 and a 2048x2048 texture with a discard of 7 will become a 64x64 texture.
if (discardlevel > MAX_DISCARD_LEVEL)
{
S32 w = head[0]; // Get the current width from the header (16)
S32 h = head[1]; // Get the current height from the header (16)
// Expand the width and height by teh difference between the discard and MAX_DISCARD_LEVEL bit shifted to the left. (Expand power of 2 textures)
w <<= MAX_DISCARD_LEVEL - discardlevel;
h <<= MAX_DISCARD_LEVEL - discardlevel;
// Set the discard level to the MAX_DISCARD_LEVEL
discardlevel = MAX_DISCARD_LEVEL;
// Scale up the texture and scale the actual data, as we just created it above, it should be fine.
raw->scale(w, h, true);
}
// </FS:minerjr>
return raw;
}