Skip to content

Harden canvas state isolation for neon HUD and ship rendering#121

Closed
serzel wants to merge 1 commit into
mainfrom
codex/fix-rendering-state-contamination-in-neon.js
Closed

Harden canvas state isolation for neon HUD and ship rendering#121
serzel wants to merge 1 commit into
mainfrom
codex/fix-rendering-state-contamination-in-neon.js

Conversation

@serzel

@serzel serzel commented Feb 18, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Prevent HUD neon rendering state (shadowColor, shadowBlur, globalCompositeOperation, globalAlpha) from leaking into ship rendering when save()/restore() nesting is imbalanced.
  • Make neon drawing paths robust against surrounding code that may mis-manage canvas state so visuals (weapon halo) always reflect game state, not residual HUD state.
  • Ensure Ship.render() never inherits composite or shadow settings from prior UI draws.

Description

  • Added resetRenderIsolationState(ctx) and withNeonIsolation(ctx, draw) to src/ui/neon.js and applied them to tubeStroke, neonLine, neonPanel, neonText, and neonBar so every neon draw path explicitly resets state before and after drawing.
  • Replaced ad-hoc save()/restore() usages inside neon code with the isolation wrapper and explicit resets to guarantee ctx.shadowBlur = 0, ctx.shadowColor = 'rgba(0,0,0,0)', ctx.globalCompositeOperation = 'source-over', and ctx.globalAlpha = 1 on exit.
  • Refactored Ship.render() in src/entities/Ship.js to add a local resetRenderState() and to wrap trail, sprite, thrust, and halo sections with try/finally blocks and explicit resets so ship drawing begins and ends with a known clean canvas state.

Testing

  • Ran node --check src/ui/neon.js and it succeeded.
  • Ran node --check src/entities/Ship.js and it succeeded.
  • Attempted an automated page render/screenshot (Playwright) but the local HTTP server startup failed in this environment and the Playwright run returned net::ERR_EMPTY_RESPONSE, so the visual smoke test did not complete.

Codex Task

@serzel serzel closed this Feb 18, 2026
@serzel
serzel deleted the codex/fix-rendering-state-contamination-in-neon.js branch February 18, 2026 21:14
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