BroadPhase issue...

BroadPhase issue...

I just started the long complicated task of integrating Havok Physics and Possibly Animation into my Custom Built Ogre3D Game Engine. I have created a Physics System with in a dll that handles all of the Havok related tasks. I then took and created a test Console Application to test out the Physics engine. Everything seems to initialize correctly however when I go to step the Simulation I get all kinds of errors:

------------------------------------------------------------------
Havok - Build (20120119)
Version 2011.3.0-r1
Base system initialized.
------------------------------------------------------------------
Havok License Keys:
Physics : PcXs (expires PERPETUAL)
Animation : PcXs (expires PERPETUAL)
------------------------------------------------------------------
World\\BroadPhaseBorder\\hkpBroadPhaseBorder.cpp(164): [0xF013323D] Assert: Entity
left the broadphase. See hkpWorldCinfo::BroadPhaseBorderBehaviour for details.S
tack trace is:
y:\\build\\20120119_200004_pcxsperpetualkeycode\\source\\common\\base\\system\\error\\hk
defaulterror.cpp(137):'hkDefaultError::message'
y:\\build\\20120119_200004_pcxsperpetualkeycode\\source\\physics\\dynamics\\world\\broa
dphaseborder\\hkpbroadphaseborder.cpp(164):'hkpBroadPhaseBorder::maxPositionExcee
dedCallback'
y:\\build\\20120119_200004_pcxsperpetualkeycode\\source\\physics\\dynamics\\world\\broa
dphaseborder\\hkpbroadphaseborder.cpp(125):'hkpBroadPhaseBorder::collidableAddedC
allback'
y:\\build\\20120119_200004_pcxsperpetualkeycode\\source\\physics\\dynamics\\phantom\\hk
pphantom.inl(31):'hkpPhantom::fireCollidableAdded'
y:\\build\\20120119_200004_pcxsperpetualkeycode\\source\\physics\\dynamics\\phantom\\hk
paabbphantom.cpp(254):'hkpAabbPhantom::addOverlappingCollidable'
y:\\build\\20120119_200004_pcxsperpetualkeycode\\source\\physics\\dynamics\\world\\util
\\broadphase\\hkpbroadphaseborderlistener.cpp(35):'hkpBroadPhaseBorderListener::ad
dCollisionPair'
y:\\build\\20120119_200004_pcxsperpetualkeycode\\source\\physics\\collide\\dispatch\\br
oadphase\\hkptypedbroadphasedispatcher.cpp(50):'hkpTypedBroadPhaseDispatcher::add
Pairs'
y:\\build\\20120119_200004_pcxsperpetualkeycode\\source\\physics\\dynamics\\world\\simu
lation\\continuous\\hkpcontinuoussimulation.inl(53):'hkpContinuousSimulation::remo
veAndAddPairs'
y:\\build\\20120119_200004_pcxsperpetualkeycode\\source\\physics\\dynamics\\world\\simu
lation\\continuous\\hkpcontinuoussimulation.cpp(950):'hkpContinuousSimulation::col
lideEntitiesBroadPhaseContinuous'
y:\\build\\20120119_200004_pcxsperpetualkeycode\\source\\physics\\dynamics\\world\\simu
lation\\continuous\\hkpcontinuoussimulation.cpp(693):'hkpContinuousSimulation::col
lideInternal'
y:\\build\\20120119_200004_pcxsperpetualkeycode\\source\\physics\\dynamics\\world\\simu
lation\\hkpsimulation.cpp(187):'hkpSimulation::collide'
y:\\build\\20120119_200004_pcxsperpetualkeycode\\source\\physics\\dynamics\\world\\simu
lation\\hkpsimulation.cpp(367):'hkpSimulation::stepDeltaTime'
y:\\build\\20120119_200004_pcxsperpetualkeycode\\source\\physics\\dynamics\\world\\hkpw
orld.cpp(2417):'hkpWorld::stepDeltaTime'
c:\\users\\james\\documents\\visual studio 2010\\projects\\game\\physicssystem\\physicss
ystem.cpp(97):'PhysicsSystem::Tick'
c:\\users\\james\\documents\\visual studio 2010\\projects\\game\\physicstest\\physicstes
t.cpp(16):'wmain'
f:\\dd\\vctools\\crt_bld\\self_x86\\crt\\src\\crtexe.c(552):'__tmainCRTStartup'
f:\\dd\\vctools\\crt_bld\\self_x86\\crt\\src\\crtexe.c(370):'wmainCRTStartup'
(null)(0):'BaseThreadInitThunk'
(null)(0):'RtlInitializeExceptionChain'
(null)(0):'RtlInitializeExceptionChain'

I copied the code from one of the step by step stand alone demos and just placed the code into different methods.

// PhysicsSystem.cpp : Defines the exported functions for the DLL application.
//

#include "stdafx.h"
#include "PhysicsSystem.h"
#include

using namespace std;

// This is the constructor of a class that has been exported.
// see PhysicsSystem.h for the class definition
PhysicsSystem::PhysicsSystem()
{
return;
}

PhysicsSystem::~PhysicsSystem()
{
// Release the reference on the world
world->removeReference();

hkBaseSystem::quit();
hkMemoryInitUtil::quit();
}

PhysicsSystem* PhysicsSystem::Singleton()
{
static PhysicsSystem* instance;
if(!instance)
instance = new PhysicsSystem();
return instance;
}

void PhysicsSystem::InitiatePhysicsWorld()
{
memoryRouter = hkMemoryInitUtil::initDefault( &baseMalloc, hkMemorySystem::FrameInfo(1024 * 1024) );
hkBaseSystem::init( memoryRouter, errorReport );
{
hkpWorldCinfo info;
info.setBroadPhaseWorldSize(3000);
world = new hkpWorld( info );

// Register all collision agents
// It's important to register collision agents before adding any entities to the world.
hkpAgentRegisterUtil::registerAllAgents( world->getCollisionDispatcher() );
}
}

void PhysicsSystem::PhysicsTest()
{
hkpRigidBody* rigidBody;
{
// Create a box 1 by 2 by 3
hkVector4 halfExtents; halfExtents.set(0.5f, 1.0f, 1.5f);
hkpBoxShape* boxShape = new hkpBoxShape(halfExtents);

hkpRigidBodyCinfo bodyCinfo;
bodyCinfo.m_shape = boxShape;

// Calculate the mass properties for the shape
const hkReal boxMass = 10.0f;
hkpMassProperties massProperties;
hkpInertiaTensorComputer::computeShapeVolumeMassProperties(boxShape, boxMass, massProperties);

bodyCinfo.setMassProperties(massProperties);

// Create the rigid body
rigidBody = new hkpRigidBody(bodyCinfo);

// No longer need the reference on the boxShape, as the rigidBody now owns it
boxShape->removeReference();
}

this->AddEntityToSimulation(rigidBody);

// No longer need the ref of rigidBody - as the world now owns it
rigidBody->removeReference();
}

void PhysicsSystem::RemoveEntityFromSimulation(hkpEntity* entity)
{
world->removeEntity(entity);
}

void PhysicsSystem::AddEntityToSimulation(hkpEntity* entity)
{
world->addEntity(entity);
}

hkpWorld* PhysicsSystem::GetPhysicsWorld()
{
return world;
}

void PhysicsSystem::Tick(float deltaTime)
{
world->stepDeltaTime(deltaTime);

//const hkArray& activeIslands = world->getActiveSimulationIslands();
//for (int i = 0; i < activeIslands.getSize(); ++i)
//{
// const hkArray& entities = activeIslands[i]->getEntities();
// for (int j = 0; j < entities.getSize(); ++j)
// {
// hkpRigidBody* rigidBody = hkpGetRigidBody(entities[j]->getCollidable());
// if (rigidBody != nullptr)
// {
// //sync code here
// //cout << "My Position is: X -" << rigidBody->getPosition().x << "\\n";
// }
// }
//}
}

// Keycode
#include

// Productfeatures
// We're using only physics - we undef products even if the keycode is present so
// that we don't get the usual initialization for these products.
#undef HK_FEATURE_PRODUCT_AI
#undef HK_FEATURE_PRODUCT_ANIMATION
#undef HK_FEATURE_PRODUCT_CLOTH
#undef HK_FEATURE_PRODUCT_DESTRUCTION
#undef HK_FEATURE_PRODUCT_BEHAVIOR

// Also we're not using any serialization/versioning so we don't need any of these.
#define HK_EXCLUDE_FEATURE_SerializeDeprecatedPre700
#define HK_EXCLUDE_FEATURE_RegisterVersionPatches
//#define HK_EXCLUDE_FEATURE_RegisterReflectedClasses
#define HK_EXCLUDE_FEATURE_MemoryTracker

// This include generates an initialization function based on the products
// and the excluded features.
#include

8 post / 0 nuovi
Ultimo contenuto
Per informazioni complete sulle ottimizzazioni del compilatore, consultare l'Avviso sull'ottimizzazione

Hello,

This is the same issue as described in this thread.

Kissy

Ok I am still getting an issue with my objects going out of the BroadPhase. As a result it Freezes my engine up. It then corrects it's self after a few seconds and then everything runs smoothly after that.

This is the error I get:
ERROR: World\BroadPhaseBorder\hkpBroadPhaseBorder.cpp(178): [0x267BC474] Warning
: Entity left the broadphase and has been changed to fixed motion type. See hkpW
orldCinfo::BroadPhaseBorderBehaviour for details.

This error just repeats over and over for 2 or 3 seconds and then it stops. When it stops the Physics Engine starts working as expected again and the Client unfreezes. The Ogre Head that I sync with the sphere falls from the sky after like it should and the spheres that I setup to be able to shoot work and collide like they should.

Here is my Physics Inilization code:

memoryRouter = hkMemoryInitUtil::initDefault( hkMallocAllocator::m_defaultMallocAllocator, hkMemorySystem::FrameInfo(1024 * 1024) );
hkBaseSystem::init( memoryRouter, errorReport );
{
// The world cinfo contains global simulation parameters, including gravity, solver settings etc.
hkpWorldCinfo worldInfo;

// Set the simulation type of the world to multi-threaded.
worldInfo.m_simulationType = hkpWorldCinfo::SIMULATION_TYPE_CONTINUOUS;

// Flag objects that fall "out of the world" to be automatically removed - just necessary for this physics scene
worldInfo.m_broadPhaseBorderBehaviour = hkpWorldCinfo::BROADPHASE_BORDER_FIX_ENTITY;

worldInfo.setBroadPhaseWorldSize(6000);

world = new hkpWorld(worldInfo);

// Register all collision agents
// It's important to register collision agents before adding any entities to the world.
hkpAgentRegisterUtil::registerAllAgents( world->getCollisionDispatcher() );
}

For setBroadPhaseWorldSize I had that set to 3000 but was getting this same error so I increased it to 6000 and I am still getting the error.

And here is the sphere creation code (This is for the sphere that I sync the Ogre Head to which is what causes the problem I believe):

const hkReal radius = 1.5f;
const hkReal sphereMass = 150.0f;

hkVector4 relPos( 0.0f,radius + 2000.0f, 50.0f );

hkpRigidBodyCinfo info;
hkpMassProperties massProperties;
hkpInertiaTensorComputer::computeSphereVolumeMassProperties(radius, sphereMass, massProperties);

info.m_mass = massProperties.m_mass;
info.m_centerOfMass = massProperties.m_centerOfMass;
info.m_inertiaTensor = massProperties.m_inertiaTensor;
info.m_shape = new hkpSphereShape( radius );
info.m_position.setAdd4(posy, relPos );
info.m_motionType = hkpMotion::MOTION_BOX_INERTIA;

info.m_qualityType = HK_COLLIDABLE_QUALITY_BULLET;

hkpRigidBody* sphereRigidBody = new hkpRigidBody( info );
g_ball = sphereRigidBody;

physicsWorld->addEntity( sphereRigidBody );
sphereRigidBody->removeReference();
info.m_shape->removeReference();

hkVector4 vel( 0.0f,4.9f, 0.0f );
sphereRigidBody->setLinearVelocity( vel );

Did you try with a static object first ?
For instance this :

		hkVector4 groundRadii( 70.0f, 2.0f, 140.0f );
		hkpConvexShape* shape = new hkpBoxShape( groundRadii , 0 );

		hkpRigidBodyCinfo ci;

		ci.m_shape = shape;
		ci.m_motionType = hkpMotion::MOTION_FIXED;
		ci.m_position = hkVector4( 0.0f, -2.0f, 0.0f );
		ci.m_qualityType = HK_COLLIDABLE_QUALITY_FIXED;

		m_pWorld->addEntity( new hkpRigidBody( ci ) )->removeReference();
		shape->removeReference();

Then add a non-static object on top and visualise everything with the Visual Debugger.

Kissy

No I didn't do any of that. Infact I don't even have the Visual Debugger setup to work yet. I do have a box for the ground and walls around the ground though. But I haven't disabled the dynamic content yet to see if it still freezes.

You should check out the VDB stuff.
It allow you to understand sometimes why you have weird Physic going on :)

Kissy

Ok thanks to Kissy's suggestion I found out that it was the walls that was causing it. I took the code that I am using for testing from one of the demos and it had walls around the testing area that a sphere would roll into. Well for some reason those walls were causing the issue. The Physics Engine now runs smoothly from start to finish so far anyways...

Nice to hear that you solved your issue :)

Accedere per lasciare un commento.