diff --git a/src/graphics/engine/particle.cpp b/src/graphics/engine/particle.cpp index 2642b74e..5f8b1601 100644 --- a/src/graphics/engine/particle.cpp +++ b/src/graphics/engine/particle.cpp @@ -641,22 +641,22 @@ void CParticle::GetRankFromChannel(int &channel) int uniqueStamp = (channel>>16)&0xffff; channel &= 0xffff; - assert(channel >= 0 && channel < MAXPARTICULE*MAXPARTITYPE); - - if (!m_particle[channel].used) assert(!!"Tried to access invalid particle channel (used=false) !\n"); - if (m_particle[channel].uniqueStamp != uniqueStamp) assert(!!"Tried to access invalid particle channel (uniqueStamp changed) !\n"); + if (channel < 0 || channel >= MAXPARTICULE*MAXPARTITYPE) throw std::runtime_error("Tried to access invalid particle channel (invalid ID)"); + if (!m_particle[channel].used) throw std::runtime_error("Tried to access invalid particle channel (used=false)"); + if (m_particle[channel].uniqueStamp != uniqueStamp) throw std::runtime_error("Tried to access invalid particle channel (uniqueStamp changed)"); } bool CParticle::ParticleExists(int channel) { - int uniqueStamp = (channel>>16)&0xffff; - channel &= 0xffff; - - assert(channel >= 0 && channel < MAXPARTICULE*MAXPARTITYPE); - - if (!m_particle[channel].used) return false; - if (m_particle[channel].uniqueStamp != uniqueStamp) return false; - return true; + try + { + GetRankFromChannel(channel); + return true; + } + catch (const std::runtime_error& e) + { + return false; + } } void CParticle::DeleteRank(int rank) diff --git a/src/graphics/engine/particle.h b/src/graphics/engine/particle.h index 55ef7baa..ec8d8820 100644 --- a/src/graphics/engine/particle.h +++ b/src/graphics/engine/particle.h @@ -297,7 +297,11 @@ public: protected: //! Removes a particle of given rank void DeleteRank(int rank); - //! Adapts the channel so it can be used as an offset in m_particle + /** + * \brief Adapts the channel so it can be used as an offset in m_particle + * \param channel Channel number to process, will be modified to be index of particle in m_particle + * \throw std::runtime_error if this particle does not exist any more + **/ void GetRankFromChannel(int &channel); //! Draws a triangular particle void DrawParticleTriangle(int i); diff --git a/src/object/old_object.cpp b/src/object/old_object.cpp index 7c2682d8..d945c5c8 100644 --- a/src/object/old_object.cpp +++ b/src/object/old_object.cpp @@ -2975,6 +2975,7 @@ void COldObject::UpdateSelectParticle() // Updates lens. for ( i=0 ; i<4 ; i++ ) { + if (m_partiSel[i] == -1) continue; pos[i] = Math::Transform(m_objectPart[0].matWorld, pos[i]); dim[i].y = dim[i].x; m_particle->SetParam(m_partiSel[i], pos[i], dim[i], zoom[i], angle, 1.0f);