[colobot] 97/145: Fixed some particle crashes after 99a831a03be068dd0c40ee3a7ca162cdcfb5e85d
Didier Raboud
odyx at moszumanska.debian.org
Mon Jul 11 12:56:21 UTC 2016
This is an automated email from the git hooks/post-receive script.
odyx pushed a commit to branch debian/master
in repository colobot.
commit d80fa387b9949bc8fad407a4847862f88973ce94
Author: krzys-h <krzys_h at interia.pl>
Date: Sat May 28 16:16:48 2016 +0200
Fixed some particle crashes after 99a831a03be068dd0c40ee3a7ca162cdcfb5e85d
---
src/graphics/engine/particle.cpp | 24 ++++++++++++------------
src/graphics/engine/particle.h | 6 +++++-
src/object/old_object.cpp | 1 +
3 files changed, 18 insertions(+), 13 deletions(-)
diff --git a/src/graphics/engine/particle.cpp b/src/graphics/engine/particle.cpp
index 2642b74..5f8b160 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 55ef7ba..ec8d882 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 7c2682d..d945c5c 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);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/colobot.git
More information about the Pkg-games-commits
mailing list