stepMultithreaded() crash

stepMultithreaded() crash

Hello. I'm currently attempting to duplicate the simple command line multithreaded demo for physics, however I get a crash atstepMultithreaded() and am not sure how to remedy it.Here is my code:

void HK_CALL run(){

		 // Initialize.

		 running=true;
		 hkMallocAllocator baseMalloc;

		 hkMemoryRouter* memoryRouter = hkMemoryInitUtil::initDefault(

			 hkMallocAllocator::m_defaultMallocAllocator, hkMemorySystem::FrameInfo( 2000000 ) );

		 hkBaseSystem::init( memoryRouter, errorReport );  
		 // Threading..............................................

		 hkJobThreadPool* threadPool;

		 int totalNumThreadsUsed;
		 // Get the number of physical threads available on the system

		 hkHardwareInfo hwInfo;

		 hkGetHardwareInfo(hwInfo);

		 totalNumThreadsUsed = hwInfo.m_numThreads;
		 // We use one less than this for our thread pool, because we must also use this thread for our simulation

		 hkCpuJobThreadPoolCinfo threadPoolCinfo;

		 threadPoolCinfo.m_numThreads = totalNumThreadsUsed - 1;
		 // This line enables timers collection, by allocating 200 Kb per thread.  If you leave this at its default (0),

		 // timer collection will not be enabled.

		 threadPoolCinfo.m_timerBufferPerThreadAllocation = 200000;

		 threadPool = new hkCpuJobThreadPool( threadPoolCinfo );
		 // We also need to create a Job queue. This job queue will be used by all Havok modules to run multithreaded work.

		 // Here we only use it for physics.

		 hkJobQueueCinfo jqinfo;

		 jqinfo.m_jobQueueHwSetup.m_numCpuThreads = totalNumThreadsUsed;

		 hkJobQueue* jobQueue = new hkJobQueue(jqinfo);
		 //

		 // Enable monitors for this thread.

		 //
		 // Monitors have been enabled for thread pool threads already (see above comment).

		 hkMonitorStream::getInstance().resize(200000);

		 //............................................................
		 // Create World...............................................
		 // Set world properties.

		 hkpWorldCinfo winfo;
		 winfo.m_simulationType = hkpWorldCinfo::SIMULATION_TYPE_MULTITHREADED;

		 winfo.setupSolverInfo(hkpWorldCinfo::SOLVER_TYPE_4ITERS_MEDIUM);

		 winfo.m_solverTau = 0.6f;

		 winfo.m_gravity.set(0, -9.8f, 0); // Default value, you could not write this

		 winfo.m_collisionTolerance = 0.1f; // Default value 
		 // Flag objects that fall "out of the world" to be automatically removed - just necessary for this physics scene

		 winfo.m_broadPhaseBorderBehaviour = hkpWorldCinfo::BROADPHASE_BORDER_REMOVE_ENTITY;

		 winfo.setBroadPhaseWorldSize(1000.0f); // Default value

		 // We need an hkpTreeBroadPhase to perform culling.

		 winfo.m_broadPhaseType = hkpWorldCinfo::BROADPHASE_TYPE_TREE;
		 world = new hkpWorld( winfo );
		 // When the simulation type is SIMULATION_TYPE_MULTITHREADED, in the debug build, the sdk performs checks

		 // to make sure only one thread is modifying the world at once to prevent multithreaded bugs. Each thread

		 // must call markForRead / markForWrite before it modifies the world to enable these checks.

		 world->markForWrite();
		 // Register all collision agents

		 // It's important to register collision agents before adding any entities to the world.

		 hkpAgentRegisterUtil::registerAllAgents( world->getCollisionDispatcher() );
		 // Enable stabilized solver and pre-stabilize inertias

		 hkpConstraintStabilizationUtil::setConstraintsSolvingMethod(world, hkpConstraintAtom::METHOD_STABILIZED);
		 world->registerWithJobQueue( jobQueue );

		 //............................................................
		 // Add the static environment to the world.

		 ptr_environment->Load_Create_Environment( MAP_WTEST_1_HAVOK, world );
		 // Create the scenery listener.

		 Physics_Scenery::CreateListener_EndOfStep();
		 // Add any game rigid bodies from the world manager.

		 add_RigidBody_Scenery();

		 add_RigidBody_Player();
		 // Register all the physics viewers

		 hkpPhysicsContext::registerAllPhysicsProcesses();
		 // Context.....................................................
		 //

		 // Initialize the VDB

		 //

		 hkArray contexts;
		 // : Register physics specific visual debugger processes

		 // By default the VDB will show debug points and lines, however some products such as physics and cloth have additional viewers

		 // that can show geometries etc and can be enabled and disabled by the VDB app.

		 hkpPhysicsContext* context;

		 {

			 // The visual debugger so we can connect remotely to the simulation

			 // The context must exist beyond the use of the VDB instance, and you can make

			 // whatever contexts you like for your own viewer types.

			 context = new hkpPhysicsContext();

			 hkpPhysicsContext::registerAllPhysicsProcesses(); // all the physics viewers

			 context->addWorld(world); // add the physics world so the viewers can see it

			 contexts.pushBack(context);
			 // Now we have finished modifying the world, release our write marker.

			 world->unmarkForWrite();

		 }
		 // Set up the visual debugger

		 hkVisualDebugger* visualDebugger = new hkVisualDebugger(contexts);

		 visualDebugger->serve();
		 //.............................................................
		 // A stopwatch (64-bit timer) for waiting until the real time has passed

		 hkStopwatch stopWatch;

		 stopWatch.start();

		 hkReal lastTime = stopWatch.getElapsedSeconds();
		 // Update as if running at 60 frames per second.

		 const int numStepsPerSecond = 60;

		 const hkReal timeStep = 1.0f / hkReal(numStepsPerSecond);
		 // Loop.

		 while( running ){
			 world->markForWrite();

                         UpdateStuff( timeStep );
			 // :

			 // Step the physics world. This single call steps using this thread and all threads

			 // in the threadPool. For other products you add jobs, call process all jobs and wait for completion.

			 // See the multithreading chapter in the user guide for details

			 {

				 world->stepMultithreaded( jobQueue, threadPool, timeStep );

			 }
			 // Step the visual debugger. We first synchronize the timer data

			 context->syncTimers( threadPool );

			 visualDebugger->step();
			 // Clear accumulated timer data in this thread and all slave threads

			 hkMonitorStream::getInstance().reset();

			 threadPool->clearTimerData();
			 // Pause until the actual time has passed

			 while (stopWatch.getElapsedSeconds() < lastTime + timeStep);

			 lastTime += timeStep;

		 }
		 // Destroy. 
		 delete ptr_player_character;
		 // : cleanup physics

		 {

			 world->markForWrite();

			 world->removeReference();

		 }

		 visualDebugger->removeReference();
		 // Contexts are not reference counted at the base class level by the VDB as

		 // they are just interfaces really. So only delete the context after you have

		 // finished using the VDB.

		 context->removeReference();
		 delete jobQueue;
		 //

		 // Clean up the thread pool

		 //

		 threadPool->removeReference();
		 hkBaseSystem::quit();

		 hkMemoryInitUtil::quit();

	 }
}

Am I missing something? It always crashes at the call to stepMultithreaded() and then breaks on the first thingafter that. Also, I'm not performing any other Havok multithreadding operations as my impression from themanuals are that you don't have to if using stepMultithreaded().
Thanks for your time and I'd really appreciate any help.

publicaciones de 3 / 0 nuevos
Último envío
Para obtener más información sobre las optimizaciones del compilador, consulte el aviso sobre la optimización.

I've expanded the call to stepMultithreaded() as it is described in the user guide to:

{

					 //world->stepMultithreaded( jobQueue, threadPool, timeStep );
					 // Place the initial physics jobs on the job queue

					 world->initMtStep( jobQueue, timeStep );
					 // Tell the worker threads to start processing all jobs

					 threadPool->processAllJobs( jobQueue );
						 // Also use this thread to process all jobs

						 jobQueue->processAllJobs( );
					 // Wait for the worker threads to complete

					 threadPool->waitForCompletion();
					 // Finish the step, including performing continuous simulation

					 world->finishMtStep( jobQueue, threadPool );
				 }
Now, the crash happens at the 2nd call to jobQueue->processAllJobs(). Here is the error output:
First-chance exception at 0x00d31fbd in MT_Engine.exe: 0xC0000005: Access violation reading location 0x099ac59c.

Unhandled exception at 0x00d31fbd in MT_Engine.exe: 0xC0000005: Access violation reading location 0x099ac59c.

The program '[28664] MT_Engine.exe: Native' has exited with code -1073741819 (0xc0000005).
And here is the console output:
y:build20120119_200004_pcxsperpetualkeycodesourcecommonbasesystemerrorhk

defaulterror.cpp(137):'hkDefaultError::message'
y:build20120119_200004_pcxsperpetualkeycodesourcephysicsinternalbroadphase

treebroadphasehkptreebroadphase.cpp(782):'hkpTreeBroadPhase::updateHandlesStan

dalone'
y:build20120119_200004_pcxsperpetualkeycodesourcephysicsinternalbroadphase

treebroadphasehkptreebroadphase.cpp(1155):'hkpTreeBroadPhase::updateAabbs'
y:build20120119_200004_pcxsperpetualkeycodesourcephysicsinternalbroadphase

treebroadphasehkptreebroadphase.cpp(1131):'hkpTreeBroadPhase::updateAabbsUint3

2'
y:build20120119_200004_pcxsperpetualkeycodesourcephysicsdynamicsworldsimu

lationcontinuoushkpcontinuoussimulation.cpp(825):'hkpContinuousSimulation::col

lideEntitiesBroadPhaseContinuousFindPairs'
y:build20120119_200004_pcxsperpetualkeycodesourcephysicsdynamicsworldsimu

lationmultithreadedcpuhkpcpubroadphasejob.cpp(117):'hkpSingleThreadedJobsOnIs

land::cpuBroadPhaseJob'
y:build20120119_200004_pcxsperpetualkeycodesourcephysicsdynamicsworldsimu

lationmultithreadedhkpmultithreadedsimulation.cpp(199):'hkpMultiThreadedSimula

tion::processNextJob'
y:build20120119_200004_pcxsperpetualkeycodesourcecommonbasethreadjobqueue

hkjobqueue.cpp(555):'hkJobQueue::processAllJobs'
c:userspublicdocumentsopengl_studymultithreaded_engine_1opengl_harnessope

ngl_harnessphysicsmanager.cpp(809):'PhysicsManager::run'
c:userspublicdocumentsopengl_studymultithreaded_engine_1opengl_harnessope

ngl_harnessphysicsmanager.h(35):'PhysicsTBB::execute'
(null)(0):'tbb::task_scheduler_init::default_num_threads'
(null)(0):'tbb::task_scheduler_init::default_num_threads'
(null)(0):'tbb::internal::thread_sleep_v3'
(null)(0):'tbb::internal::thread_sleep_v3'
(null)(0):'beginthreadex'
(null)(0):'beginthreadex'
(null)(0):'BaseThreadInitThunk'
(null)(0):'RtlInitializeExceptionChain'
(null)(0):'RtlInitializeExceptionChain'

I've explored the output more and found some very nice responses from Havok telling me that I have an issue with my objects going out of the broadphase and being removed.I will continue to post my findings untill I've resolved the issue.

Inicie sesión para dejar un comentario.