Skip to content

[SOLID] [M21] Inject font atlas; mutex-guard graphics_presets #803

Description

@MichaelFisher1997

Part of #776 — SOLID architecture debt umbrella.
Phase: P3 · Finding: M21

Problem

Two mutable globals violate DIP:

  • modules/engine-ui/src/font.zig:8 var active_atlas — hidden global pointer, no synchronization, set by UISystemManager and read on every drawText/measureTextWidth.
  • modules/game-core/src/settings/json_presets.zig:51 pub var graphics_presets — process-wide mutable list, no mutex. Loaded once at startup, read from game-ui settings screens.

Evidence

(Full evidence and file:line citations are in the umbrella #776.)

Fix

  1. Font atlas: pass it via injection through the UI draw context instead of a global.
  2. graphics_presets: gate behind an accessor that holds a mutex, or make immutable after load.

Verification

  • nix develop --command zig build test (includes shader validation)
  • If rendering-touching: capture headless screenshot baseline before/after (-Dskip-present)
  • If behavior-preserving refactor: golden-output test must stay green

Constraints

  • Small reviewable PR targeting dev; conventional commit (refactor: / feat:)
  • Preserve current behavior unless this issue explicitly changes it
  • Keep worker-thread RHI isolation intact (no RHI calls off main thread)

Notes

Currently safe only because UI runs single-threaded on the main thread after single-shot init — an undocumented invariant. Fix removes the latent hazard.

Tracking: #776

Metadata

Metadata

Assignees

No one assigned

    Labels

    automated-auditIssues found by automated opencode audit scansbugSomething isn't workingdocumentationImprovements or additions to documentationengineenhancementNew feature or requestgame

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions