Blank Images While Drawing Mini Program Posters
·
2 min read
·
251
Words
·
-Views
-Comments
Our mini program generates posters by downloading multiple web images (PNG/GIF) and drawing them via Painter. Some posters randomly showed black or blank regions. Here’s what we found.
Symptoms
- Certain images rendered as black, while others displayed correctly.
- Network traces on real devices showed missing image requests for the blank regions.
Investigation
- Painter downloads remote assets into the mini program’s temp directory, then caches them with an LRU strategy (6 MB cap by default).
- Large GIFs (~23 MB) triggered the LRU cleanup logic:
- PNG downloads completed first (fast, small).
- When the GIF finished, Painter attempted to cache it; the GIF exceeded the 6 MB limit.
- The LRU logic deleted existing temp files (including the PNG) to stay under the cap.
- Subsequent canvas draws referenced files that had been deleted, resulting in blank regions.
- Upon re-entering the poster screen, Painter reused cached paths without re-downloading, but the referenced files no longer existed—leading to empty drawings.
Fix
- Upgrading to the latest Painter where
lru
defaults tofalse
resolved the issue in our case.
Lessons & Workarounds
- Painter’s download + LRU deletion runs asynchronously. Large files can evict required assets before the canvas draw executes.
- Options:
- Disable LRU (but monitor the mini program’s overall temp storage, capped at ~200 MB).
- Customize Painter to run downloads sequentially or to increase the cache threshold.
Despite the fix, be aware that once temp storage hits 200 MB, downloads may fail. Implement cleanup or increase the threshold if you fork Painter.