mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-07 09:33:51 +00:00
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:
parent
10e77f1c2e
commit
c1af157587
1 changed files with 11 additions and 0 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue