From d127053e21dd2c43f19a24741c59121e12b3f0f5 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Wed, 6 May 2026 06:56:32 -0700 Subject: [PATCH] fix(objects): bound populateBiome density and asset scale ranges Same defensive guards as scatter: cap per-asset count at 50k to prevent editor freeze under a high-density biome, and ensure scale range preconditions (a distPos(0.0f, 1.0f); std::uniform_real_distribution distRot(0.0f, 360.0f); @@ -224,8 +225,19 @@ int ObjectPlacer::populateBiome(const BiomeVegetation& vegetation, // Calculate object count from density (per 100x100 area) float areaFactor = (tileSize * tileSize) / 10000.0f; int count = static_cast(asset.density * areaFactor); + // Cap per-asset count — a runaway density value would freeze the + // editor and exceed sensible vertex/draw limits for the tile. + if (count > 50'000) count = 50'000; + if (count <= 0) continue; - std::uniform_real_distribution distScale(asset.minScale, asset.maxScale); + // Ensure the scale distribution preconditions hold (a < b, both + // positive). Asset definitions are normally edited in code but we + // also load them from JSON in some setups. + float minS = std::isfinite(asset.minScale) ? asset.minScale : 1.0f; + float maxS = std::isfinite(asset.maxScale) ? asset.maxScale : minS + 0.01f; + if (minS <= 0.0f) minS = 0.01f; + if (maxS < minS) maxS = minS + 0.01f; + std::uniform_real_distribution distScale(minS, maxS); for (int i = 0; i < count; i++) { float u = distPos(rng);