mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-16 16:10:36 +00:00
BLP decodes into the shared scratch BEFORE it calls the allocator, so the size cave (which fires from the allocator) was always too late for it — a 2048x2048 BLP overran the scratch on this client. A pre-hook on the decompressor FUN_005A8430, which carries the level-0 dimensions, grows the scratch first and repoints the caller's already-copied scratch slot at the new buffer, or fails cleanly for a texture the GPU cannot hold. It acts only when the slot IS the shared scratch; the IMG path decodes into its own right-sized buffer and is left alone. GrowScratch now retires the previous buffer one generation late (frees at the next growth) so any unaccounted holder reads stale bytes, not unmapped memory. Verified: a 2048x2048 DXT1 BLP renders and grows the scratch to 2048. The async force-load path shoves a read that never fit the shared buffer into a 512 KiB static fallback with no size check — the engine bug behind "big BLPs crash". The hook refuses a request larger than the fallback; the texture stays blank. Growing the fallback to fit was tried and reverted: the read runs on the engine's async reader thread, which has no crash handler, and a read into a right-sized heap buffer froze then killed the process where the same read into the oversized shared buffer does not — not yet isolated. Consequence: an uncompressed BLP file larger than the shared buffer (2 MiB stock, 32 MiB with VanillaHelpers) does not load; DXT stays far under it and TGA is synchronous, so only a pathological input is lost. Verified: a 2900x2900 uncompressed BLP draws nothing and does not freeze.