diff --git a/tools/editor/object_placer.cpp b/tools/editor/object_placer.cpp index 3d29dfa4..86b4d0ef 100644 --- a/tools/editor/object_placer.cpp +++ b/tools/editor/object_placer.cpp @@ -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(center.x * 100 + center.y * 37 + objects_.size())); std::uniform_real_distribution distAngle(0.0f, 6.2831853f); std::uniform_real_distribution distDist(0.0f, 1.0f);