Blank Images While Drawing Mini Program Posters

Diagnosing Painter’s LRU cache and large GIF downloads that lead to blank poster images, plus mitigations.

May 29, 2022 · 2 min read · 251 Words · -Views -Comments · Programming
WeChat Mini Program Canvas 🇨🇳 阅读中文版
Read with AI

Choose an AI assistant

ChatGPT Open in a new tab with the article link and prompt
Claude Copy the prompt, then open Claude

Open Claude
Trouble reading the article?

If the prompt is missing, copy the full prompt below into your AI assistant. If the AI cannot read the article, paste the visible passage you want to discuss and add your question.

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

  1. Painter downloads remote assets into the mini program’s temp directory, then caches them with an LRU strategy (6 MB cap by default).
  2. 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.
  3. 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 to false 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:
    1. Disable LRU (but monitor the mini program’s overall temp storage, capped at ~200 MB).
    2. 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.

References

Authors
Developer, digital product enthusiast, tinkerer, sharer, open source lover