diff --git a/src/graphics/engine/particle.cpp b/src/graphics/engine/particle.cpp index e63a8c6a..f5c254e3 100644 --- a/src/graphics/engine/particle.cpp +++ b/src/graphics/engine/particle.cpp @@ -3740,4 +3740,24 @@ Color CParticle::GetFogColor(Math::Vector pos) return result; } +void CParticle::CutObjectLink(CObject* obj) +{ + for (int i = 0; i < MAXPARTICULE*MAXPARTITYPE; i++) + { + if (!m_particle[i].used) continue; + + if (m_particle[i].objLink == obj) + { + // If the object this particle's coordinates are linked to doesn't exist anymore, remove the particle + DeleteRank(i); + } + + if (m_particle[i].objFather == obj) + { + // If the object that spawned this partcle doesn't exist anymore, remove the link + m_particle[i].objFather = nullptr; + } + } +} + } // namespace Gfx diff --git a/src/graphics/engine/particle.h b/src/graphics/engine/particle.h index 03707a9c..08dfc432 100644 --- a/src/graphics/engine/particle.h +++ b/src/graphics/engine/particle.h @@ -291,6 +291,9 @@ public: //! Draws all the particles void DrawParticle(int sheet); + //! Indicates that the object binds to the particle no longer exists, without deleting it + void CutObjectLink(CObject* obj); + protected: //! Removes a particle of given rank void DeleteRank(int rank); diff --git a/src/object/old_object.cpp b/src/object/old_object.cpp index dbbb3890..9655ad7b 100644 --- a/src/object/old_object.cpp +++ b/src/object/old_object.cpp @@ -203,6 +203,7 @@ void COldObject::DeleteObject(bool bAll) if ( !bAll ) { m_engine->GetPyroManager()->CutObjectLink(this); + m_particle->CutObjectLink(this); if ( m_bSelect ) {