St0rM3r
24-09-2008 23:24:31
Hi !
I have a crash in Newton.dll when I set up 100 (by instance, but the crash is appearing when there are more than ~30) OgreNewt bodies at the same position (set with setPositionOrientation).
My collisionCallback does nothing.
Callstack information :
Newton.dll!0069f5b7()
Here is my body initialization class :
Thank you for you help guys !
I have a crash in Newton.dll when I set up 100 (by instance, but the crash is appearing when there are more than ~30) OgreNewt bodies at the same position (set with setPositionOrientation).
My collisionCallback does nothing.
Callstack information :
Newton.dll!0069f5b7()
Here is my body initialization class :
#include "stdmodelafx.h"
#include "CollisionObject.h"
#include "CollisionCallback.h"
extern SOCMODEL_API OgreNewt::World* Physics;
using namespace soc;
using namespace Ogre;
const OgreNewt::MaterialID *CollisionObject::collisionMaterial = 0;
OgreNewt::MaterialPair *CollisionObject::collisionLink = 0;
OgreNewt::MaterialPair *CollisionObject::collisionLink2 = 0;
void CollisionObject::Init()
{
Physics = new OgreNewt::World();
AxisAlignedBox physicsBox(Vector3(-999999999.9, -999999999.9, -999999999.9), Vector3(999999999.9, 999999999.9, 999999999.9));
Physics->setWorldSize(physicsBox);
collisionMaterial = new OgreNewt::MaterialID(Physics);
OgreNewt::MaterialPair* collisionLink = new OgreNewt::MaterialPair(Physics, Physics->getDefaultMaterialID(), collisionMaterial);
collisionLink->setContactCallback(new CollisionCallback());
OgreNewt::MaterialPair* collisionLink2 = new OgreNewt::MaterialPair(Physics, collisionMaterial, collisionMaterial);
collisionLink2->setContactCallback(new CollisionCallback());
}
void CollisionObject::Destroy()
{
OgreNewt::Debugger::getSingleton().deInit();
delete collisionLink;
delete collisionLink2;
delete Physics;
}
CollisionObject::CollisionObject()
{
body = 0;
col = 0;
}
CollisionObject::~CollisionObject()
{
disableCollisionDetect();
}
void CollisionObject::disableCollisionDetect()
{
if (body)
{
body->freeze();
delete body;
body = 0;
}
}
void CollisionObject::updateBody(Ogre::SceneNode *node)
{
if (body && node)
{
Ogre::Vector3 pos = node->getPosition();
Ogre::Quaternion orient = node->getOrientation();
body->setPositionOrientation(pos, orient);
}
}
void CollisionObject::enableCollidable(Ogre::SceneNode *node, Ogre::Entity *entity)
{
if (node && entity)
{
Ogre::Vector3 vSize = GetPhysicalBounding(node, entity);
col = GetPhysicalBody(Physics, node);
body = new OgreNewt::Body(Physics, col);
body->setAutoFreeze(0);
delete col;
Ogre::Vector3 inertia = OgreNewt::MomentOfInertia::CalcBoxSolid(vSize.length(), vSize);
body->setMassMatrix(vSize.length(), inertia);
body->setUserData(this);
updateBody(node);
body->unFreeze();
}
}
void CollisionObject::enableCollision(Ogre::SceneNode *node, Ogre::Entity *entity)
{
enableCollidable(node, entity);
body->setMaterialGroupID(collisionMaterial);
}
OgreNewt::Collision *CollisionObject::GetPhysicalBody(OgreNewt::World *world, Ogre::SceneNode *node) const
{
return new OgreNewt::CollisionPrimitives::ConvexHull(Physics, node);
}
Ogre::Vector3 CollisionObject::GetPhysicalBounding(Ogre::SceneNode *node, Ogre::Entity *entity) const
{
return entity->getBoundingBox().getSize() * node->getScale();
}
Thank you for you help guys !