From d1e92970537793ca82f6e12fa933370a66c77273 Mon Sep 17 00:00:00 2001 From: Paul Sladen Date: Tue, 23 Jun 2009 21:57:34 +0300 Subject: [PATCH] * Add WatchdogExit() to take care of deadlocks in library shutdown --- debian/changelog | 1 + openBVE/OpenBve/Program.cs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 0 deletions(-) diff --git a/debian/changelog b/debian/changelog index 5c60816..788efae 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,5 +1,6 @@ openbve (1.0.6.7-0ubuntu1) unreleased; urgency=low + * Add WatchdogExit() to take care of deadlocks in library shutdown * New upstream version (1.0.6.7) -- Paul Sladen Sun, 7 Jun 2009 02:54:00 +0000 diff --git a/openBVE/OpenBve/Program.cs b/openBVE/OpenBve/Program.cs index 51fc216..add5686 100644 --- a/openBVE/OpenBve/Program.cs +++ b/openBVE/OpenBve/Program.cs @@ -1,6 +1,7 @@ using System; using Tao.OpenGl; using Tao.Sdl; +using System.Threading; using System.Windows.Forms; namespace OpenBve { @@ -14,6 +15,15 @@ namespace OpenBve { internal static bool UseFilesystemHierarchyStandard = false; private static bool SdlWindowCreated = false; + internal static void WatchdogExit() + { + int delay = 5000; // milliseconds + Console.Error.WriteLine("WatchdogExit: starting timer"); + System.Threading.Thread.Sleep(delay); + Console.Error.WriteLine("WatchdogExit: Something did not shutdown quickly enough, forcing exit"); + Environment.Exit(1); + } + //// main [STAThread] internal static void Main(string[] Args) { @@ -66,6 +76,13 @@ namespace OpenBve { if(SdlWindowCreated & Interface.CurrentOptions.FullscreenMode) { Sdl.SDL_SetVideoMode(Interface.CurrentOptions.WindowWidth, Interface.CurrentOptions.WindowHeight, 32, Sdl.SDL_OPENGL | Sdl.SDL_DOUBLEBUF); } + + // Start a watchdog timer, so that even if SDL/OpenAL hang freeing buffers, + // the program will still successfully force a quit. + Thread Watchdog = new Thread(new ThreadStart(WatchdogExit)); + Watchdog.IsBackground = true; + Watchdog.Start(); + TextureManager.UnuseAllTextures(); Asynchronous.Deinitialize(); PluginManager.UnloadPlugin(); @@ -84,6 +101,7 @@ namespace OpenBve { } System.Diagnostics.Process.Start(Assembly.Location, RestartProcessArguments); } + Environment.Exit(0); } //// get exception text -- 1.6.0.4