Skip to content

Reference count netcode_init, default zeroed configs, deterministic simulator rng#147

Merged
gafferongames merged 1 commit into
mainfrom
small-sharp-edges
Jul 9, 2026
Merged

Reference count netcode_init, default zeroed configs, deterministic simulator rng#147
gafferongames merged 1 commit into
mainfrom
small-sharp-edges

Conversation

@gafferongames

Copy link
Copy Markdown
Contributor

Summary

Remaining small-sharp-edges work (Tier 2 + 3):

  • netcode_init/netcode_term are reference counted — multiple subsystems in one application can init/term independently. A second init previously tripped a debug-only assert and silently re-ran WSAStartup/sodium_init in release; an unbalanced term now returns cleanly instead of underflowing.
  • Zeroed configs get default allocators — forgetting netcode_default_client_config/netcode_default_server_config was a NULL-deref in the create paths; it now just means default malloc/free, matching how netcode_read_packet already defended.
  • Deterministic network simulator — per-instance seeded xorshift64* replaces global rand(). Simulator runs are reproducible across runs and platforms, isolated from application rand() usage, and reset restores the seed. netcode_random_float is removed (simulator-only; soak/profile have their own local helpers).

New tests: test_init_and_defaults, test_network_simulator_determinism (two identical simulators with 25% loss, 50ms jitter, 25% duplication must drop/delay/duplicate identically). Suite is now 40 tests.

Test plan

  • Local macOS: Release, Debug, ASan+UBSan all pass 40/40
  • CI green on all 9 jobs

🤖 Generated with Claude Code

…imulator rng

Three ergonomics and reproducibility fixes:

- netcode_init/netcode_term are reference counted, so multiple subsystems
  in the same application can init and term independently. Previously a
  second init was assert-only and silently re-ran platform init in release.

- netcode_client_create/netcode_server_create default the allocator
  functions if the caller passes a zeroed config instead of calling
  netcode_default_*_config first. Previously this was a NULL deref.

- The network simulator uses a per-instance seeded xorshift64* instead of
  global rand(). Simulator behavior is now deterministic across runs and
  isolated from application use of rand(). netcode_random_float is removed;
  it was only used by the simulator.

Adds test_init_and_defaults and test_network_simulator_determinism
(suite is now 40 tests).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@gafferongames gafferongames merged commit a340fb2 into main Jul 9, 2026
8 checks passed
@gafferongames gafferongames deleted the small-sharp-edges branch July 9, 2026 13:36
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.

1 participant