fix(objects): guard ObjectPlacer::scatter against bad inputs

Same defensive guards now applied to NPC scatter: reject NaN/inf
center/radius, cap count at 100k (prevents editor freeze on huge
inputs), and ensure minScale < maxScale so uniform_real_distribution
preconditions hold.
This commit is contained in:
Kelsi 2026-05-06 06:55:43 -07:00
parent 10e77f1c2e
commit c1af157587

View file

@ -176,6 +176,17 @@ void ObjectPlacer::deleteSelected() {
void ObjectPlacer::scatter(const glm::vec3& center, float radius, int count,
float minScale, float maxScale) {
if (activePath_.empty()) return;
// Defensive bounds — UI sliders cap these, but the function is also
// callable programmatically. count > 100k would freeze the editor;
// minScale >= maxScale violates uniform_real_distribution preconditions.
if (count <= 0 || count > 100'000) return;
if (!std::isfinite(radius) || radius < 0.0f) return;
if (!std::isfinite(center.x) || !std::isfinite(center.y) ||
!std::isfinite(center.z)) return;
if (!std::isfinite(minScale) || !std::isfinite(maxScale)) return;
if (minScale <= 0.0f) minScale = 0.01f;
if (maxScale < minScale) maxScale = minScale + 0.01f;
std::mt19937 rng(static_cast<uint32_t>(center.x * 100 + center.y * 37 + objects_.size()));
std::uniform_real_distribution<float> distAngle(0.0f, 6.2831853f);
std::uniform_real_distribution<float> distDist(0.0f, 1.0f);