From 1876592d225edf097e9e56726c088c602fa8c825 Mon Sep 17 00:00:00 2001 From: Irlan Date: Sun, 23 Jun 2019 15:29:47 -0300 Subject: [PATCH] Delete world body contacts if world gets detached. --- include/bounce/cloth/cloth.h | 5 ----- src/bounce/cloth/cloth.cpp | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/include/bounce/cloth/cloth.h b/include/bounce/cloth/cloth.h index 288c724..4e7136c 100644 --- a/include/bounce/cloth/cloth.h +++ b/include/bounce/cloth/cloth.h @@ -204,11 +204,6 @@ inline b3Vec3 b3Cloth::GetGravity() const return m_gravity; } -inline void b3Cloth::SetWorld(b3World* world) -{ - m_world = world; -} - inline const b3World* b3Cloth::GetWorld() const { return m_world; diff --git a/src/bounce/cloth/cloth.cpp b/src/bounce/cloth/cloth.cpp index 0152bac..cdec9be 100644 --- a/src/bounce/cloth/cloth.cpp +++ b/src/bounce/cloth/cloth.cpp @@ -293,6 +293,23 @@ b3Cloth::~b3Cloth() } } +void b3Cloth::SetWorld(b3World* world) +{ + if (!world && m_world) + { + // Destroy body contacts + b3ParticleBodyContact* c = m_contactManager.m_particleBodyContactList.m_head; + while (c) + { + b3ParticleBodyContact* boom = c; + c = c->m_next; + m_contactManager.Destroy(boom); + } + } + + m_world = world; +} + b3Particle* b3Cloth::CreateParticle(const b3ParticleDef& def) { void* mem = m_particleBlocks.Allocate();