Remove particle forces if it gets destroyed

This commit is contained in:
Irlan 2019-06-05 13:49:40 -03:00
parent 5ee66d645e
commit 07ee080310
3 changed files with 24 additions and 2 deletions

View File

@ -46,6 +46,9 @@ public:
//
b3Force* GetNext();
//
virtual bool HasParticle(const b3Particle* particle) const = 0;
protected:
friend class b3List2<b3Force>;
friend class b3Cloth;

View File

@ -67,6 +67,8 @@ public:
float32 GetDampingStiffness() const;
b3Vec3 GetActionForce() const;
bool HasParticle(const b3Particle* particle) const;
private:
friend class b3Force;
friend class b3Cloth;
@ -127,4 +129,9 @@ inline b3Vec3 b3SpringForce::GetActionForce() const
return m_f;
}
inline bool b3SpringForce::HasParticle(const b3Particle* particle) const
{
return m_p1 == particle || m_p2 == particle;
}
#endif

View File

@ -257,8 +257,7 @@ b3Cloth::~b3Cloth()
{
b3Force* f0 = f;
f = f->m_next;
f0->~b3Force();
b3Free(f0);
b3Force::Destroy(f0);
}
}
@ -280,6 +279,19 @@ b3Particle* b3Cloth::CreateParticle(const b3ParticleDef& def)
void b3Cloth::DestroyParticle(b3Particle* particle)
{
B3_ASSERT(particle->m_vertex == ~0);
b3Force* f = m_forceList.m_head;
while (f)
{
b3Force* f0 = f;
f = f->m_next;
if (f0->HasParticle(particle))
{
m_forceList.Remove(f0);
b3Force::Destroy(f0);
}
}
m_particleTree.RemoveNode(particle->m_treeId);