Skip to content

Fix crash on Play Game from reversed random bounds - #218

Merged
BenjaFriend merged 1 commit into
mainfrom
fix/random-reversed-bounds
Oct 24, 2026
Merged

BenjaFriend merged 1 commit into
mainfrom
fix/random-reversed-bounds

Conversation

@BenjaFriend

@BenjaFriend BenjaFriend commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Crash: Clicking Play Game in the editor hit a Debug assert in MSVC's std::uniform_real_distribution (min <= max). Sandbox::Game::LightingTest passed min.z = 15 and max.z = -15 to Random::GetRandomVec3.
  • Sandbox fix: The z bounds in LightingTest are now in the right order. The spawn area is the same.
  • Engine fix: RandomBetween and GetRandomFloat now sort their bounds with std::minmax before they build the distribution. GetRandomVec3 calls GetRandomFloat, so it is covered too. This applies to both Random and RandomStream. Before, reversed bounds were undefined behavior and asserted in Debug. The header docs now say the bounds can be in either order.
  • Tests: Added Catch2 sections for reversed int, float and vec3 bounds (including the exact Sandbox case) and for equal bounds.

Test plan

  • CoreTests.exe "[utils]" (Debug, MSVC): all 17830 assertions in 8 test cases pass
  • scripts/check_comment_style.py passes
  • Launch Sandbox and click Play Game: no crash (tested by author)

🤖 Generated with Claude Code

LightingTest passed a min.z greater than max.z to Random::GetRandomVec3.
MSVC's uniform_real_distribution asserts min <= max in Debug, so the
editor crashed when it started the game.

Fix the Sandbox bounds, and make Random/RandomStream sort the bounds
before they build a distribution so reversed bounds can never crash.
Add regression tests for reversed and equal bounds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@BenjaFriend
BenjaFriend merged commit 96e9f20 into main Oct 24, 2026
9 checks passed
@BenjaFriend
BenjaFriend deleted the fix/random-reversed-bounds branch October 24, 2026 23:09
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