Simulate does not return

Hello, I am using PhysX version 3.3.1 and I have the problem that when I call Simulate() during my update loop, the method never returns.

Any idea how that could happen ?

My code is pretty simple and my scene consists of a heightfield and a couple of rigid dynamic actors. Nothing too fancy.

I saw someone had the same problem on the “stackoverflow” forums, here
[url]c++ - PhysX - simulate() never ends if GPU used - Stack Overflow

But the solution proposed by the user is just to revert to a previous version of physX, I thought I better ask here before jumping to conclusions.

Regards
ChrysP

Just to clarify, the thread I mention above is similar not exactly the same . I am not trying to do anything with CUDA or particles etc. Also my application doesn’t freeze. It just seems to not ever get out of the “simulate” method.

I am attaching the Physx Visual debugger and i can see my scene and all objects in it but they don’t move (because of simulate not progressing i guess).

Just in case someone is interested, here is my code , pretty much all take from the first sample in the SDK.

this initializes all the physics stuff

void cAWPhysics::Initialize()
{
	bool recordMemoryAllocations = true;

	const bool useCustomTrackingAllocator = true;

	PxAllocatorCallback* allocator = &gDefaultAllocatorCallback;

	if(useCustomTrackingAllocator)		
		allocator = GetAWAllocator();		//optional override that will track memory allocations

	mpPxFoundation = PxCreateFoundation(PX_PHYSICS_VERSION, *allocator, GetAWErrorCallback());
	if(!mpPxFoundation)
	{
		AWAssertMsg(false, "PxCreateFoundation failed!");
		return;
	}

	mpPxProfileZoneManager = &PxProfileZoneManager::createProfileZoneManager(mpPxFoundation);
	if(!mpPxProfileZoneManager)
	{
		AWAssertMsg(false, "PxProfileZoneManager::createProfileZoneManager failed!");
		return;
	}

	mpPxPhysics = PxCreatePhysics(PX_PHYSICS_VERSION, *mpPxFoundation, PxTolerancesScale(), recordMemoryAllocations, mpPxProfileZoneManager);
    //mpPxPhysics = PxCreateBasePhysics(PX_PHYSICS_VERSION, *mpPxFoundation, PxTolerancesScale());
	if(!mpPxPhysics)
	{
		AWAssertMsg(false, "PxCreatePhysics failed!");
		return;
	}

	if(GetOrCreateProfileZone(*mpPxFoundation))
	{
		mpPxProfileZoneManager->addProfileZone(*GetOrCreateProfileZone(*mpPxFoundation));
	}

	if(!PxInitExtensions(*mpPxPhysics))
	{
		AWAssertMsg(false, "PxInitExtensions failed!");
                return;
	}

	PxTolerancesScale toleranceScale;
	mpPxCooking = PxCreateCooking(PX_PHYSICS_VERSION, *mpPxFoundation, PxCookingParams(toleranceScale));
	if(!mpPxCooking)
	{
		AWAssertMsg(false, "PxCreateCooking failed!");
                return;
	}

#ifdef AW_DEBUG_BUILD

	if(mpPxPhysics->getPvdConnectionManager())
	{
		mpPxPhysics->getPvdConnectionManager()->addHandler(*this);
	}
#endif

	// setup default material...

    mpDefaultMaterial = new sAWPhysicsMaterial();
    mpDefaultMaterial->friction = 0.5f;
    mpDefaultMaterial->FrictionCombineMode = 0;
    mpDefaultMaterial->Restitution = 0.1f;
    mpDefaultMaterial->Density = 1.0f;
    mpDefaultMaterial->RaiseMassToPower = 1.0f;

	mpPxDefaultMaterial = mpDefaultMaterial->GetPxMaterial();
	if(!mpPxDefaultMaterial)
	{
		AWAssertMsg(false, "createMaterial failed!");
		return;
	}

	mpPxCpuDispatcher = PxDefaultCpuDispatcherCreate(mNbThreads);
	if(!mpPxCpuDispatcher)
	{
		AWAssertMsg(false, "PxDefaultCpuDispatcherCreate failed!");
		return;
	}
}

then I initialize my scene

void cAWPhysicsScene::Initialize()
{
	cAWPhysics* pAWPhysics = cAWPhysics::Get();
	PxPhysics* pPxPhysics = pAWPhysics->GetPhysics();
	
	PX_ASSERT(NULL == mpPxScene);

	PxSceneDesc sceneDesc(pPxPhysics->getTolerancesScale());
	sceneDesc.gravity = PxVec3(0.0f, -9.81f, 0.0f);
	sceneDesc.cpuDispatcher	= pAWPhysics->GetPxDefaultCpuDispatcher();
	sceneDesc.filterShader	= PxDefaultSimulationFilterShader;

	sceneDesc.flags |= PxSceneFlag::eENABLE_ACTIVETRANSFORMS;
	mpPxScene = pPxPhysics->createScene(sceneDesc);
	if(!mpPxScene)
	{
		AWAssertMsg(false, "PhysX: createScene failed!");
		return;
	}

	mpPxScene->setVisualizationParameter(PxVisualizationParameter::eSCALE, 1.0f);
	mpPxScene->setVisualizationParameter(PxVisualizationParameter::eCOLLISION_SHAPES,	1.0f);
}

and here is where i update the scene

void cAWPhysicsScene::Update(float dt)
{
   static float stepSize = 1.0f / 60.0f;

    mpPxScene->lockWrite();
    mpPxScene->simulate(stepSize);
    mpPxScene->unlockWrite();

    mpPxScene->fetchResults(true);
}

my code gets stuck on “mpPxScene->simulate(stepSize);”

but in the VDO i can see my scene just nothing moves.

Is there a reason you are locking the scene? considering I don’t think you are doing concurrent access to PhysX…

you are right , I just did that because i saw the examples doing it.
Initially I wasn’t doing it and this isn’t causing the issue (I can remove the lines and it still happens).

I did find out that by removing my heightfield from the scene the simulate now isn’t blocked anymore.
So maybe my heightfield is too big or something like that.

My dynamic actors are still not falling from the sky though. So I probably still have something missing somewhere. :( I’ll try read up on the heightfield issue. (odd that it shows correctly in the VDO though).

Okay so turns out things actually were moving just really slow.
I think my heightfields definitely need some re-thinking.