Skip to content

Remove the WebGL context loss listeners in Game#destroy - #757

Merged
samme merged 2 commits into
phaserjs:masterfrom
asger-finding:fix-context-loss-listeners-after-destroy
Oct 19, 2026
Merged

samme merged 2 commits into
phaserjs:masterfrom
asger-finding:fix-context-loss-listeners-after-destroy

Conversation

@asger-finding

Copy link
Copy Markdown
Contributor

This PR

  • is a bug fix

Describe the changes below:

Game#setUpRenderer added contextLost.bind(this) and contextRestored.bind(this) to the canvas without storing references to them, so Game#destroy can't remove them.

If a destroyed game's context was lost later (like if the browser evicts it for too many active contexts), then contextLost would throw Cannot set properties of null (setting 'contextLost'). The bound handlers are now kept on the game and removed in destroy().

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

Both listeners are removed using their original references before renderer teardown, with no unresolved issues.

No open issues 🎉

What changed in this PR

Fixes errors caused by WebGL context events firing after a game is destroyed.

Changes:

  • Stores bound context event handlers and removes both listeners before renderer teardown.
  • Documents the fix in the changelog.
File Description
src/​core/​Game.js Retains handler references and removes listeners during destruction.
CHANGELOG.md Documents the destroyed-game context-loss fix.

Review effort: Balanced

@samme
samme merged commit df2d191 into phaserjs:master Oct 19, 2026
0 of 3 checks passed
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.

3 participants