From 13078c820be0d96b96c1fa0825e4ff4b1805ecde Mon Sep 17 00:00:00 2001 From: RoosterDragon Date: Tue, 21 Apr 2015 20:27:06 +0100 Subject: [PATCH] Retry hardware cursor creation. On Windows, a spurious error sometimes occur when creating cursors. We retry a few times before before having to give up and fall back to software cursors. --- OpenRA.Renderer.Sdl2/Sdl2GraphicsDevice.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/OpenRA.Renderer.Sdl2/Sdl2GraphicsDevice.cs b/OpenRA.Renderer.Sdl2/Sdl2GraphicsDevice.cs index ab622f7e53..59cf43505a 100755 --- a/OpenRA.Renderer.Sdl2/Sdl2GraphicsDevice.cs +++ b/OpenRA.Renderer.Sdl2/Sdl2GraphicsDevice.cs @@ -144,7 +144,9 @@ namespace OpenRA.Renderer.Sdl2 var sur = (SDL2.SDL.SDL_Surface)Marshal.PtrToStructure(surface, typeof(SDL2.SDL.SDL_Surface)); Marshal.Copy(data, 0, sur.pixels, data.Length); - Cursor = SDL.SDL_CreateColorCursor(surface, hotspot.X, hotspot.Y); + // This call very occasionally fails on Windows, but often works when retried. + for (var retries = 0; retries < 3 && Cursor == IntPtr.Zero; retries++) + Cursor = SDL.SDL_CreateColorCursor(surface, hotspot.X, hotspot.Y); if (Cursor == IntPtr.Zero) throw new InvalidDataException("Failed to create cursor: {0}".F(SDL.SDL_GetError())); }