jpcsupplies / Economy_mod

Basic Economy System for Space Engineers
13 stars 12 forks source link

Buying ship with connector attached causes crash #176

Closed midspace closed 6 years ago

midspace commented 6 years ago

Buying a ship while it is connected via a connector to another ship on a dedicated server will cause the server to crash.

017-12-05 13:18:48.992 - Thread:   1 ->  GC Memory: 379,365,016 B
2017-12-05 13:19:18.992 - Thread:   1 ->  GC Memory: 379,495,296 B
2017-12-05 13:19:37.708 - Thread:   5 ->  Exception occured: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at hkpWorld.removeConstraint(hkpWorld* , hkBool* , hkpConstraintInstance* )
   at Havok.HkWorld.RemoveConstraint(HkConstraint constraint)
   at Sandbox.Engine.Physics.MyPhysicsBody.RemoveConstraint(HkConstraint constraint)
   at Sandbox.Game.Entities.Cube.MyShipConnector.RemoveConstraint(MyShipConnector otherConnector, HkConstraint constraint)
   at Sandbox.Game.Entities.Cube.MyShipConnector.DetachInternal()
   at Sandbox.Game.Entities.Cube.MyShipConnector.Detach(Boolean synchronize)
   at Sandbox.Game.Entities.Cube.MyShipConnector.OnOwnershipChanged()
   at Sandbox.Game.Entities.MyCubeBlock.ChangeOwner(Int64 owner, MyOwnershipShareModeEnum shareMode)
   at Sandbox.Game.Entities.MyCubeGrid.OnChangeGridOwner(Int64 playerId, MyOwnershipShareModeEnum shareMode)
   at Sandbox.Game.Entities.MyCubeGrid.ChangeGridOwner(Int64 playerId, MyOwnershipShareModeEnum shareMode)
   at Sandbox.Game.Entities.MyCubeGrid.VRage.Game.ModAPI.IMyCubeGrid.ChangeGridOwnership(Int64 playerId, MyOwnershipShareModeEnum shareMode)
   at Economy.scripts.Messages.MessageShipSale.<>c__DisplayClass5_2.<ProcessServer>b__2()
   at ParallelTasks.DelegateWork.DoWork(WorkData workData)
   at ParallelTasks.WorkItem.DoWork(Int32 expectedID)
   at ParallelTasks.BackgroundWorker.WorkLoop()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   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()
2017-12-05 13:19:37.709 - Thread:   5 ->  Hiding window
2017-12-05 13:19:37.709 - Thread:   5 ->  Hiding window done
2
midspace commented 6 years ago

This sucks, because we currently use a single method to change the ownership of an entire grid. Having to check for connector blocks will require us checking every single block.

midspace commented 6 years ago

This might be because it's in a background thread.

midspace commented 6 years ago

Confirmed, its a threading issue. Havok doesn't want to play thread-ball. Trying to disconnect the connectors in the background thread would not have worked.