From dacacdf130681f353f231cd11d4a0d3130af48ab Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 2 May 2021 22:31:49 +0100 Subject: [PATCH] Remove global fallback to software cursors on error. We now only fall back for the specific cursors that failed. --- OpenRA.Game/Graphics/CursorManager.cs | 46 +++++++++++++-------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/OpenRA.Game/Graphics/CursorManager.cs b/OpenRA.Game/Graphics/CursorManager.cs index 02dec8bc55..fa34f5a051 100644 --- a/OpenRA.Game/Graphics/CursorManager.cs +++ b/OpenRA.Game/Graphics/CursorManager.cs @@ -106,34 +106,33 @@ namespace OpenRA.Graphics // Dispose any existing cursors to avoid leaking native resources ClearHardwareCursors(); - try + foreach (var kv in cursors) { - foreach (var kv in cursors) + var template = kv.Value; + for (var i = 0; i < template.Sprites.Length; i++) { - var template = kv.Value; - for (var i = 0; i < template.Sprites.Length; i++) + if (template.Cursors[i] != null) + template.Cursors[i].Dispose(); + + // Calculate the padding to position the frame within sequenceBounds + var paddingTL = -(template.Bounds.Location - template.Sprites[i].Offset.XY.ToInt2()); + var paddingBR = template.PaddedSize - new int2(template.Sprites[i].Bounds.Size) - paddingTL; + + try { - if (template.Cursors[i] != null) - template.Cursors[i].Dispose(); - - // Calculate the padding to position the frame within sequenceBounds - var paddingTL = -(template.Bounds.Location - template.Sprites[i].Offset.XY.ToInt2()); - var paddingBR = template.PaddedSize - new int2(template.Sprites[i].Bounds.Size) - paddingTL; - template.Cursors[i] = CreateHardwareCursor(kv.Key, template.Sprites[i], paddingTL, paddingBR, -template.Bounds.Location); } + catch (Exception e) + { + Log.Write("debug", "Failed to initialize hardware cursor for {0}.", template.Name); + Log.Write("debug", "Error was: " + e.Message); + + Console.WriteLine("Failed to initialize hardware cursor for {0}.", template.Name); + Console.WriteLine("Error was: " + e.Message); + template.Cursors[i] = null; + } } } - catch (Exception e) - { - Log.Write("debug", "Failed to initialize hardware cursors. Falling back to software cursors."); - Log.Write("debug", "Error was: " + e.Message); - - Console.WriteLine("Failed to initialize hardware cursors. Falling back to software cursors."); - Console.WriteLine("Error was: " + e.Message); - - ClearHardwareCursors(); - } hardwareCursorsDoubled = graphicSettings.CursorDouble; } @@ -177,10 +176,11 @@ namespace OpenRA.Graphics if (cursor != null && frame >= cursor.Cursors.Length) frame %= cursor.Cursors.Length; - if (cursor == null || isLocked) + var hardwareCursor = cursor?.Cursors[frame]; + if (hardwareCursor == null || isLocked) Game.Renderer.Window.SetHardwareCursor(null); else - Game.Renderer.Window.SetHardwareCursor(cursor.Cursors[frame]); + Game.Renderer.Window.SetHardwareCursor(hardwareCursor); } public void Render(Renderer renderer)