Fixes crash for too many particles

The maximum number of particles was unbound. It's bound by the
number of maximum vertices per vertex buffer.
This commit is contained in:
Vladislav Belov
2026-06-20 21:45:55 +02:00
parent ec8b420abc
commit 54b529ddac
+12 -1
View File
@@ -273,7 +273,18 @@ CParticleEmitterType::CParticleEmitterType(const VfsPath& path, CParticleManager
// Upper bound on number of particles depends on maximum rate and lifetime
m_MaxLifetime = m_Variables[VAR_LIFETIME]->Max(*this);
m_MaxParticles = ceil(m_Variables[VAR_EMISSIONRATE]->Max(*this) * m_MaxLifetime);
const uint32_t maximumNumberOfParticles{
static_cast<uint32_t>(ceil(m_Variables[VAR_EMISSIONRATE]->Max(*this) * m_MaxLifetime))};
constexpr uint16_t maximumSupportedNumberOfParticles{
std::numeric_limits<uint16_t>::max() / 6};
if (maximumNumberOfParticles > maximumSupportedNumberOfParticles)
{
LOGERROR("Too many particles per particle system: '%s' (%u/%u)",
path.string8(), maximumNumberOfParticles, maximumSupportedNumberOfParticles);
m_MaxParticles = maximumSupportedNumberOfParticles;
}
else
m_MaxParticles = maximumNumberOfParticles;
// Compute the worst-case bounds of all possible particles,