when i call removeEntity to remove multi bodys,it's have a assert while the last body

when i call removeEntity to remove multi bodys,it's have a assert while the last body

the assert info is this:

System\Error\hkError.cpp(33): [0x2C66F2D8] Error: Reference count error on object 06FE69F0 with ref count of 0 in removeReference.
* Are you calling delete instead of removeReference?
* Have you called removeReference too many times?
* In a multithreaded environment, what is the hkReferencedObject lock mode you use (see setLockMode())?
* Is this a valid object?
* Do you have more than 32768 references? (unlikely)

 this is my remove code:

mys3_void MYSAPI mys3_instance_physic_havok_body::mys3RemovePhysicBodys(const mys3_uint* objs_hash,mys3_uint count)
{
 m_pWorld->markForWrite();
 for (mys3_uint i = 0;i < count;++i)
 {
 stdext::hash_map<mys3_uint,mys3_physic_body>::iterator it = m_PhysicBodyMap.find(objs_hash[i]);
 if(it != m_PhysicBodyMap.end())
 {
 if (i == (count - 1))
 {
 DebugBreak();
 }
 if(it->second.pRigidBody->getWorld())
 {
 it->second.pRigidBody->getWorld()->removeEntity(it->second.pRigidBody);//while (i == count - 1),it will show me a assert
 }
 }
 stdext::hash_map<hkpShape*,hkpShape*>::iterator itShape = m_PhysicShapeMap.find(it->second.pShape);
 if(itShape != m_PhysicShapeMap.end())
 {
 it->second.pShape->removeReference();
 m_PhysicShapeMap.erase(itShape);
 }
 m_PhysicBodyMap.erase(it);
 }
 }
 m_pWorld->unmarkForWrite();
}

how can i solve this assert?

4 posts / novo 0
Último post
Para obter mais informações sobre otimizações de compiladores, consulte Aviso sobre otimizações.

i am sorry,i have already solved this problem.i found out that removeEntity will remove body and shape's ref the same time.:p

Hi Jins l.--

I'm glad you figured out your crash. Unless you have a specific reason for maintaining a map of shapes, your m_PhysicShapeMap probably isn't be necessary, because you can get a reference to a rigid body's shape directly. Given an hkpRigidBody* rigidBody, its shape is rigidBody->getCollidable()->getShape(). Hope that helps!

--Tim

thank you,Tim. I will take your advice

Deixar um comentário

Faça login para adicionar um comentário. Não é membro? Inscreva-se hoje mesmo!