TorchAPI / Torch

An extensible modding framework and improved client/DS for Space Engineers. Still a work in progress!
Apache License 2.0
146 stars 76 forks source link

HandleException doesn't always work #246

Closed j-mie closed 2 years ago

j-mie commented 6 years ago

Torch Version: v1.3.0.59-134-g93fa822 SE Version: 1.187.89

Expected Behavior

What did you expect to happen? The exception to be handled and the server to auto restart

Observed Behavior

What actually happened? The exception was not handled and the server crashed without restarting

Other Information

Stack Trace:

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at hkpConstraintInstance.getRuntime(hkpConstraintInstance* )
   at Havok.HkCustomWheelConstraintData.GetCurrentAngle(HkConstraint constraint)
   at Sandbox.Game.Entities.Cube.MyMotorSuspension.BreakingConstraintChanged()
   at System.Action`1.Invoke(T obj)
   at VRage.Sync.SyncBase.RaiseValueChanged(Boolean notify)
   at VRage.Sync.Sync`2.SetValue(T& newValue, Boolean validate, Boolean ignoreSyncDirection, Boolean received)
   at Sandbox.Game.Entities.Cube.MyMotorSuspension.Update()
   at Sandbox.Game.GameSystems.MyGridWheelSystem.UpdateBeforeSimulation()
   at Sandbox.Game.Entities.Cube.MyCubeGridSystems.UpdateBeforeSimulation()
   at Sandbox.Game.Entities.MyCubeGrid.UpdateBeforeSimulation()
   at <UpdateBeforeSimulation>b__7_0(MyEntity )
   at VRage.Collections.MyDistributedUpdater`2.Iterate(Action`1 p)
   at Sandbox.Game.Entities.MyEntities.UpdateBeforeSimulation()
   at Sandbox.Game.World.MySector.UpdateBeforeSimulation()
   at UpdateComponents_0(Object )
   at Sandbox.Game.World.MySession.Update(MyTimeSpan updateTime)
   at Sandbox.MySandboxGame.Update()
   at Sandbox.Engine.Platform.Game.UpdateInternal()
   at RunSingleFrame_0(Object )
   at Sandbox.Engine.Platform.FixedLoop.<>c__DisplayClass1.<Run>b__0()
   at Sandbox.Engine.Platform.GenericLoop.Run(VoidAction tickCallback)
   at Sandbox.Engine.Platform.Game.RunLoop()
   at Sandbox.MySandboxGame.Run(Boolean customRenderLoop, Action disposeSplashScreen)
   at Torch.VRageGame.DoStart()
   at Torch.VRageGame.Run()
   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()

My theory is that the game is running in another AppDomain? Hence AppDomain.CurrentDomain.UnhandledException += HandleException; not working?

Jimmacle commented 6 years ago

The game is definitely all in one AppDomain. It's likely something to do with Havok being native code so exceptions may not be handled the same way.

j-mie commented 6 years ago

@Jimmacle https://stackoverflow.com/a/4759831 looks useful.