Fixed some particle crashes after 99a831a03b

master
krzys-h 2016-05-28 16:16:48 +02:00
parent 89b495c667
commit d80fa387b9
3 changed files with 18 additions and 13 deletions

View File

@ -641,22 +641,22 @@ void CParticle::GetRankFromChannel(int &channel)
int uniqueStamp = (channel>>16)&0xffff; int uniqueStamp = (channel>>16)&0xffff;
channel &= 0xffff; channel &= 0xffff;
assert(channel >= 0 && channel < MAXPARTICULE*MAXPARTITYPE); 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].used) assert(!!"Tried to access invalid particle channel (used=false) !\n"); if (m_particle[channel].uniqueStamp != uniqueStamp) throw std::runtime_error("Tried to access invalid particle channel (uniqueStamp changed)");
if (m_particle[channel].uniqueStamp != uniqueStamp) assert(!!"Tried to access invalid particle channel (uniqueStamp changed) !\n");
} }
bool CParticle::ParticleExists(int channel) bool CParticle::ParticleExists(int channel)
{ {
int uniqueStamp = (channel>>16)&0xffff; try
channel &= 0xffff; {
GetRankFromChannel(channel);
assert(channel >= 0 && channel < MAXPARTICULE*MAXPARTITYPE); return true;
}
if (!m_particle[channel].used) return false; catch (const std::runtime_error& e)
if (m_particle[channel].uniqueStamp != uniqueStamp) return false; {
return true; return false;
}
} }
void CParticle::DeleteRank(int rank) void CParticle::DeleteRank(int rank)

View File

@ -297,7 +297,11 @@ public:
protected: protected:
//! Removes a particle of given rank //! Removes a particle of given rank
void DeleteRank(int 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); void GetRankFromChannel(int &channel);
//! Draws a triangular particle //! Draws a triangular particle
void DrawParticleTriangle(int i); void DrawParticleTriangle(int i);

View File

@ -2975,6 +2975,7 @@ void COldObject::UpdateSelectParticle()
// Updates lens. // Updates lens.
for ( i=0 ; i<4 ; i++ ) for ( i=0 ; i<4 ; i++ )
{ {
if (m_partiSel[i] == -1) continue;
pos[i] = Math::Transform(m_objectPart[0].matWorld, pos[i]); pos[i] = Math::Transform(m_objectPart[0].matWorld, pos[i]);
dim[i].y = dim[i].x; dim[i].y = dim[i].x;
m_particle->SetParam(m_partiSel[i], pos[i], dim[i], zoom[i], angle, 1.0f); m_particle->SetParam(m_partiSel[i], pos[i], dim[i], zoom[i], angle, 1.0f);