Proper way to clean up contacts?
Posted: Mon Sep 10, 2012 6:44 am
When I modify one of my StaticMeshes, I use the following code to make sure any physics objects touching it don't end up floating in mid-air:
This code runs on a different thread than the physics update though and it seems to be causing a null reference exception:
I assume the physics engine really doesn't like me messing with the contacts during an update. Is there a better way to go about this?
Code: Select all
foreach(var pair in mesh.Pairs)
{
if(pair.EntityA != null)
pair.EntityA.ActivityInformation.Activate();
if(pair.EntityB != null)
pair.EntityB.ActivityInformation.Activate();
pair.ClearContacts();
}
Code: Select all
Object reference not set to an instance of an object.
at BEPUphysics.Constraints.Collision.ContactPenetrationConstraint.SolveIteration()
at BEPUphysics.Constraints.SolverGroups.SolverGroup.SolveUpdateable(EntitySolverUpdateable item, Int32& activeConstraints)
at BEPUphysics.Constraints.Collision.NonConvexContactManifoldConstraint.SolveIteration()
at BEPUphysics.SolverSystems.Solver.UnsafeSolveIteration(SolverUpdateable updateable)
at BEPUphysics.SolverSystems.Solver.UpdateSingleThreaded()
at BEPUphysics.MultithreadedProcessingStage.Update()
at BEPUphysics.Space.DoTimeStep()
at BEPUphysics.Space.Update(Single dt)
at Craft.Physics.Update(GameTime gameTime)
at Craft.World.Update(GameTime gameTime)
at Craft.GameScreen.Update(GameTime gameTime)
at Craft.ScreenManager.Update(GameTime gameTime)
at Craft.Engine.GameLoop()
at SlimDX.Windows.MessagePump.IdleHandler.OnIdle(Object sender, EventArgs e)
at System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FDoIdle(Int32 grfidlef)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at SlimDX.Windows.MessagePump.Run(Form form, MainLoop mainLoop)
at Craft.Program.Main(String[] args)
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()