From 54b529ddaca21f926d9250c466b088f0e8266900 Mon Sep 17 00:00:00 2001 From: Vladislav Belov Date: Sat, 20 Jun 2026 21:45:55 +0200 Subject: [PATCH] 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. --- source/graphics/ParticleEmitterType.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/source/graphics/ParticleEmitterType.cpp b/source/graphics/ParticleEmitterType.cpp index 033e54e3e8..6715aa5eee 100644 --- a/source/graphics/ParticleEmitterType.cpp +++ b/source/graphics/ParticleEmitterType.cpp @@ -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(ceil(m_Variables[VAR_EMISSIONRATE]->Max(*this) * m_MaxLifetime))}; + constexpr uint16_t maximumSupportedNumberOfParticles{ + std::numeric_limits::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,