diff --git a/Barotrauma/BarotraumaShared/SharedSource/Screens/GameScreen.cs b/Barotrauma/BarotraumaShared/SharedSource/Screens/GameScreen.cs index be3e4bb12..3dc8dfac2 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Screens/GameScreen.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Screens/GameScreen.cs @@ -25,7 +25,7 @@ namespace Barotrauma private static readonly ParallelOptions parallelOptions = new ParallelOptions { - MaxDegreeOfParallelism = Math.Max(4,Environment.ProcessorCount - 1), + MaxDegreeOfParallelism = Math.Max(1,Environment.ProcessorCount - 1), }; #if CLIENT diff --git a/Libraries/Farseer Physics Engine 3.5/Collision/DynamicTree.cs b/Libraries/Farseer Physics Engine 3.5/Collision/DynamicTree.cs index 6bc690f09..9753764d6 100644 --- a/Libraries/Farseer Physics Engine 3.5/Collision/DynamicTree.cs +++ b/Libraries/Farseer Physics Engine 3.5/Collision/DynamicTree.cs @@ -1145,4 +1145,4 @@ namespace FarseerPhysics.Collision } } } -} \ No newline at end of file +} diff --git a/Libraries/Farseer Physics Engine 3.5/Dynamics/ContactManager.cs b/Libraries/Farseer Physics Engine 3.5/Dynamics/ContactManager.cs index 1c47b8c05..8c7d9bd9e 100644 --- a/Libraries/Farseer Physics Engine 3.5/Dynamics/ContactManager.cs +++ b/Libraries/Farseer Physics Engine 3.5/Dynamics/ContactManager.cs @@ -27,9 +27,10 @@ * 3. This notice may not be removed or altered from any source distribution. */ -using System.Collections.Generic; using FarseerPhysics.Collision; using FarseerPhysics.Dynamics.Contacts; +using System.Collections.Generic; +using System.Threading; namespace FarseerPhysics.Dynamics { @@ -61,6 +62,8 @@ namespace FarseerPhysics.Dynamics public int CollideMultithreadThreshold = 64; #endregion + // This will ensure only one thread will work on ContactList so that we wont mess up these stuff + private readonly SemaphoreSlim contactManagerSignal = new SemaphoreSlim(1); /// /// Fires when a contact is created @@ -249,6 +252,8 @@ namespace FarseerPhysics.Dynamics internal void Destroy(Contact contact) { + contactManagerSignal.Wait(100); + Fixture fixtureA = contact.FixtureA; Fixture fixtureB = contact.FixtureB; Body bodyA = fixtureA.Body; @@ -310,6 +315,8 @@ namespace FarseerPhysics.Dynamics // Insert into the pool. contact.Next = _contactPoolList.Next; _contactPoolList.Next = contact; + + contactManagerSignal.Release(); } internal void Collide() @@ -610,4 +617,4 @@ namespace FarseerPhysics.Dynamics } #endif } -} \ No newline at end of file +} diff --git a/Libraries/Farseer Physics Engine 3.5/Dynamics/Contacts/Contact.cs b/Libraries/Farseer Physics Engine 3.5/Dynamics/Contacts/Contact.cs index c79e46edd..6e2eaaaa0 100644 --- a/Libraries/Farseer Physics Engine 3.5/Dynamics/Contacts/Contact.cs +++ b/Libraries/Farseer Physics Engine 3.5/Dynamics/Contacts/Contact.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2017 Kastellanos Nikolaos +// Copyright (c) 2017 Kastellanos Nikolaos /* Original source Farseer Physics Engine: * Copyright (c) 2014 Ian Qvist, http://farseerphysics.codeplex.com @@ -496,4 +496,4 @@ namespace FarseerPhysics.Dynamics.Contacts #endregion } -} \ No newline at end of file +} diff --git a/Libraries/Farseer Physics Engine 3.5/Dynamics/World.cs b/Libraries/Farseer Physics Engine 3.5/Dynamics/World.cs index 0aa2ef49a..f64765ad9 100644 --- a/Libraries/Farseer Physics Engine 3.5/Dynamics/World.cs +++ b/Libraries/Farseer Physics Engine 3.5/Dynamics/World.cs @@ -1726,4 +1726,4 @@ namespace FarseerPhysics.Dynamics } } -} \ No newline at end of file +}