mika76 / mamesaver

Mamesaver is a mame emulated screensaver - get all the good ol' games playing their demo modes while you procrastinate and enjoy!
https://mika76.github.io/mamesaver/
MIT License
36 stars 10 forks source link

Crash on shutdown #39

Closed nullpainter closed 5 years ago

nullpainter commented 5 years ago

I haven't been able to replicate, but this is in the logs. May just be a race condition:

System.InvalidOperationException: No process is associated with this object.
   at System.Diagnostics.Process.EnsureState(State state)
   at System.Diagnostics.Process.get_HasExited()
   at Mamesaver.GamePlayManager.Dispose(Boolean disposing)
   at Mamesaver.GamePlayManager.Dispose()
   at SimpleInjector.Scope.DisposeInstancesInReverseOrder(List`1 disposables, Int32 startingAsIndex)
   at SimpleInjector.Scope.DisposeAllRegisteredDisposables()
   at SimpleInjector.Scope.DisposeRecursively(Boolean operatingInException)
   at SimpleInjector.Scope.Dispose(Boolean disposing)
   at SimpleInjector.Scope.Dispose()
   at Mamesaver.Program.Main(String[] args)
2018-09-14 11:43:18.652 +12:00 [DBG] MAME started; pid: 23272
2018-09-14 11:43:18.653 +12:00 [ERR] Unable to start game
System.NullReferenceException: Object reference not set to an instance of an object.
   at Mamesaver.MameScreen.OnGameStarted(Object sender, EventArgs args)
   at Mamesaver.GamePlayManager.RunGame()
2018-09-14 11:43:21.805 +12:00 [DBG] Resetting sleep timer
2018-09-14 11:43:21.812 +12:00 [ERR] Thread exception
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'Timer'.
   at System.Timers.Timer.set_Enabled(Boolean value)
   at Mamesaver.Power.PowerManager.ResetTimer()
   at Mamesaver.Hotkeys.HotKeyManager.OnKeyDown(Object sender, KeyEventArgs e)
   at Mamesaver.Windows.UserActivityHook.KeyboardHookProc(Int32 nCode, Int32 wParam, IntPtr lParam)
nullpainter commented 5 years ago

This appears to be caused by MAME being terminated before it has fully started. Looking at the logs, there is a ~60ms window of opportunity for this to happen (!)

Usual log entries:

2018-09-14 13:02:59.762 +12:00 [INF] Invoking MAME with arguments: vastar -skip_gameinfo -nowindow -noswitchres -sleep -triplebuffer -sound none -screen "\\.\DISPLAY2" -artpath c:\code\tools\mame\artwork;C:\Users\matthew_painter\AppData\Local\Temp\Mamesaver\Layouts
2018-09-14 13:02:59.823 +12:00 [DBG] MAME started; pid: 19976
2018-09-14 13:03:02.636 +12:00 [DBG] Exiting due to mouse activity

Failure log entries:

2018-09-14 15:06:24.955 +12:00 [INF] Invoking MAME with arguments: gunbird2 -skip_gameinfo -nowindow -noswitchres -sleep -triplebuffer -sound none -screen "\\.\DISPLAY2" -artpath c:\code\tools\mame\artwork;C:\Users\matthew_painter\AppData\Local\Temp\Mamesaver\Layouts
2018-09-14 15:06:24.955 +12:00 [DBG] Releasing device context for \\.\DISPLAY3
2018-09-14 15:06:24.971 +12:00 [DBG] Releasing device context for \\.\DISPLAY2
2018-09-14 15:06:24.999 +12:00 [DBG] Stopping screen cloning
2018-09-14 15:06:25.001 +12:00 [INF] Closing primary MAME screen \\.\DISPLAY2
2018-09-14 15:06:25.003 +12:00 [ERR] Main
System.InvalidOperationException: No process is associated with this object.
   at System.Diagnostics.Process.EnsureState(State state)
   at System.Diagnostics.Process.get_HasExited()

I'm tempted just to catch InvalidOperationException in GamePlayManager.Dispose(bool).