Skip to content

fix(loader): unloadAll threw on fontfaces and never freed videos#1535

Merged
obiot merged 1 commit into
masterfrom
fix/loader-unloadall
Jul 2, 2026
Merged

fix(loader): unloadAll threw on fontfaces and never freed videos#1535
obiot merged 1 commit into
masterfrom
fix/loader-unloadall

Conversation

@obiot

@obiot obiot commented Jul 2, 2026

Copy link
Copy Markdown
Member

Three long-latent bugs in the loader's unload path, surfaced by the pre-merge review of #1534 (out of scope there, fixed here):

  1. unloadAll never freed videos — the video-cache sweep dispatched entries as type: "json" (copy-paste from the json loop above it), so the lookup missed and video assets survived every unloadAll.
  2. unloadAll threw if any fontface was loaded — the font-cache sweep used type: "font", an unknown type that hits unload()'s default throw, aborting the whole unloadAll mid-way (the obj / mtl / gltf / shader / audio sweeps never ran). Its comment also said "video resources" — same copy-paste origin.
  3. Inert DOM guard — the fontface unload case checked typeof typeof globalThis.document !== "undefined"; typeof typeof x is always "string", so the guard was permanently true.

Test

Regression test seeds videoList + fontList (with a real FontFace) and asserts unloadAll() doesn't throw and empties both caches — verified to fail against the old code (revert-check) and pass with the fix.

Full suite 4565 passed / 0 failed; eslint + tsc + biome clean.

🤖 Generated with Claude Code

Three long-latent bugs in the unload path, surfaced by #1534's pre-merge
review:

- unloadAll's video-cache sweep dispatched entries as type "json" (copy-
  paste from the loop above), so the jsonList lookup missed and video
  assets survived every unloadAll.
- unloadAll's font-cache sweep used type "font" — an unknown type that hit
  unload()'s default throw, ABORTING the whole unloadAll mid-way (obj/mtl/
  gltf/shader/audio sweeps never ran) whenever any fontface was loaded.
  (Its comment also said "video resources" — same copy-paste.)
- The fontface unload case guarded on `typeof typeof globalThis.document`
  — always "string", never "undefined" — so the DOM check was inert.

Regression test seeds videoList + fontList (real FontFace) and asserts
unloadAll doesn't throw and empties both — verified to FAIL against the
old code and pass with the fix.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019t8kP8vp58ZrvaD2FqJU6A
Copilot AI review requested due to automatic review settings July 2, 2026 11:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes three long-standing issues in the loader unload path so loader.unloadAll() reliably cleans up video and fontface assets without throwing, and documents the fix in the changelog. This aligns the loader’s cache-sweep behavior with the supported unload() asset types and prevents unloadAll() from aborting early due to an invalid type.

Changes:

  • Correct unloadAll() dispatch types for videoList ("video") and fontList ("fontface"), preventing missed unloads and avoiding the default throw path.
  • Fix an always-true DOM guard in the "fontface" unload case (typeof typeof ...typeof ...).
  • Add a regression test that seeds videoList + fontList and asserts unloadAll() doesn’t throw and clears both.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
packages/melonjs/tests/loader.spec.js Adds regression test covering unloadAll() behavior for video + fontface caches.
packages/melonjs/src/loader/loader.js Fixes fontface DOM guard and corrects unloadAll() type routing for video/fontface cache sweeps.
packages/melonjs/CHANGELOG.md Documents the unloadAll() fontface/video unload fixes and the DOM guard correction.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@obiot obiot merged commit f227956 into master Jul 2, 2026
7 checks passed
@obiot obiot deleted the fix/loader-unloadall branch July 2, 2026 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants