Skip to content

Fix canvas context state leakage in neon and render pipeline#120

Closed
serzel wants to merge 2 commits into
mainfrom
codex/fix-canvas-state-leaks-in-game
Closed

Fix canvas context state leakage in neon and render pipeline#120
serzel wants to merge 2 commits into
mainfrom
codex/fix-canvas-state-leaks-in-game

Conversation

@serzel

@serzel serzel commented Feb 18, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Eliminate canvas rendering state leaks that cause non-neon drawing (shots, particles) to inherit neon glow properties such as shadowBlur, shadowColor, globalAlpha, or altered globalCompositeOperation.
  • Make neon UI drawing functions robust and self-contained so they never rely on external context state and cannot corrupt the shared CanvasRenderingContext2D.

Description

  • Refactored src/ui/neon.js to wrap all drawing passes with withIsolatedContext(ctx, ...) and added resetGlowState(ctx) to explicitly normalize globalAlpha, globalCompositeOperation, shadowColor, and shadowBlur before use and on exit.
  • Replaced any implicit intensity multiplication and clamped intensity usage to safe bounds and removed reliance on *= style operations for globalAlpha across neon strokes.
  • Reworked src/engine/Game.js render pipeline into isolated stages: #drawGame(), #drawParticles(), and #drawShots() that each use ctx.save()/ctx.restore() with try/finally and explicitly reset glow-sensitive state after each stage.
  • Wrapped HUD rendering and drawHUD() body in protected save()/restore() blocks with explicit state cleanup in src/ui/HUD.js to prevent HUD or neon draws leaking into subsequent profiler/overlay passes.

Testing

  • Ran syntax checks: node --check src/ui/neon.js && node --check src/engine/Game.js && node --check src/ui/HUD.js, which completed successfully.
  • Started a static server and attempted a Playwright-based page load + screenshot to visually validate rendering, but the browser navigation in this environment failed with net::ERR_EMPTY_RESPONSE (visual validation not captured).

Codex Task

@serzel serzel closed this Feb 18, 2026
@serzel
serzel deleted the codex/fix-canvas-state-leaks-in-game branch February 18, 2026 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant