From 15b7ca7315f914a6c23e10da9d02a7db39ea6baf Mon Sep 17 00:00:00 2001 From: David Zhao Date: Tue, 22 Jan 2019 17:01:52 +0900 Subject: [PATCH 01/16] Fix unloadable textures causing findPosition to never end --- osu.Framework/Graphics/Textures/TextureStore.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/osu.Framework/Graphics/Textures/TextureStore.cs b/osu.Framework/Graphics/Textures/TextureStore.cs index 38b9277d3..4dd51fa3d 100644 --- a/osu.Framework/Graphics/Textures/TextureStore.cs +++ b/osu.Framework/Graphics/Textures/TextureStore.cs @@ -46,7 +46,10 @@ namespace osu.Framework.Graphics.Textures private Texture loadRaw(TextureUpload upload) { if (upload == null) return null; - + + if (upload.Width > GLWrapper.MaxTextureSize || upload.Height > GLWrapper.MaxTextureSize) + return null; + var glTexture = atlas != null ? atlas.Add(upload.Width, upload.Height) : new TextureGLSingle(upload.Width, upload.Height, manualMipmaps, filteringMode); Texture tex = new Texture(glTexture) { ScaleAdjust = ScaleAdjust }; From e16d32f740558668ef2a23e5ccd710f19ef4fce7 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Tue, 22 Jan 2019 17:02:28 +0900 Subject: [PATCH 02/16] Minimize conditions --- osu.Framework/Graphics/Textures/TextureStore.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/osu.Framework/Graphics/Textures/TextureStore.cs b/osu.Framework/Graphics/Textures/TextureStore.cs index 4dd51fa3d..1961ff529 100644 --- a/osu.Framework/Graphics/Textures/TextureStore.cs +++ b/osu.Framework/Graphics/Textures/TextureStore.cs @@ -45,10 +45,7 @@ namespace osu.Framework.Graphics.Textures private Texture loadRaw(TextureUpload upload) { - if (upload == null) return null; - - if (upload.Width > GLWrapper.MaxTextureSize || upload.Height > GLWrapper.MaxTextureSize) - return null; + if (upload == null || upload.Width > GLWrapper.MaxTextureSize || upload.Height > GLWrapper.MaxTextureSize) return null; var glTexture = atlas != null ? atlas.Add(upload.Width, upload.Height) : new TextureGLSingle(upload.Width, upload.Height, manualMipmaps, filteringMode); From 44bb6d1a11115329a3ec99826fd70f995cf28f70 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Tue, 22 Jan 2019 17:06:54 +0900 Subject: [PATCH 03/16] Nuke whitespace --- osu.Framework/Graphics/Textures/TextureStore.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Framework/Graphics/Textures/TextureStore.cs b/osu.Framework/Graphics/Textures/TextureStore.cs index 1961ff529..c1747bfe9 100644 --- a/osu.Framework/Graphics/Textures/TextureStore.cs +++ b/osu.Framework/Graphics/Textures/TextureStore.cs @@ -46,7 +46,6 @@ namespace osu.Framework.Graphics.Textures private Texture loadRaw(TextureUpload upload) { if (upload == null || upload.Width > GLWrapper.MaxTextureSize || upload.Height > GLWrapper.MaxTextureSize) return null; - var glTexture = atlas != null ? atlas.Add(upload.Width, upload.Height) : new TextureGLSingle(upload.Width, upload.Height, manualMipmaps, filteringMode); Texture tex = new Texture(glTexture) { ScaleAdjust = ScaleAdjust }; From fe30910907c3b526ede2a2dfcb11df51c36c1366 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Tue, 22 Jan 2019 18:09:38 +0900 Subject: [PATCH 04/16] Update tests to always initialize a value for MaxTextureSize by default --- osu.Framework/Graphics/OpenGL/GLWrapper.cs | 2 +- osu.Framework/Graphics/Sprites/SpriteText.cs | 8 +++++--- osu.Framework/Graphics/Textures/TextureStore.cs | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/osu.Framework/Graphics/OpenGL/GLWrapper.cs b/osu.Framework/Graphics/OpenGL/GLWrapper.cs index cf5b4add6..f330a08a1 100644 --- a/osu.Framework/Graphics/OpenGL/GLWrapper.cs +++ b/osu.Framework/Graphics/OpenGL/GLWrapper.cs @@ -38,7 +38,7 @@ namespace osu.Framework.Graphics.OpenGL /// public static bool HasContext => GraphicsContext.CurrentContext != null; - public static int MaxTextureSize { get; private set; } + public static int MaxTextureSize { get; private set; } = 4096; private static readonly Scheduler reset_scheduler = new Scheduler(null); //force no thread set until we are actually on the draw thread. diff --git a/osu.Framework/Graphics/Sprites/SpriteText.cs b/osu.Framework/Graphics/Sprites/SpriteText.cs index a3d59ea15..94698f0f0 100644 --- a/osu.Framework/Graphics/Sprites/SpriteText.cs +++ b/osu.Framework/Graphics/Sprites/SpriteText.cs @@ -587,12 +587,14 @@ namespace osu.Framework.Graphics.Sprites /// /// The character to get the texture for. /// The texture for the given character. - protected virtual Texture GetTextureForCharacter(char c) + protected virtual Texture GetTextureForCharacter(char c) => getTextureForCharacter(c) ?? GetFallbackTextureForCharacter(c); + + private Texture getTextureForCharacter(char c) { if (store == null) return null; - return store.GetCharacter(Font, c) ?? store.GetCharacter(null, c) ?? GetFallbackTextureForCharacter(c); + return store.GetCharacter(Font, c) ?? store.GetCharacter(null, c); } /// @@ -600,7 +602,7 @@ namespace osu.Framework.Graphics.Sprites /// /// The character which doesn't exist in the current font. /// The texture for the given character. - protected virtual Texture GetFallbackTextureForCharacter(char c) => GetTextureForCharacter('?'); + protected virtual Texture GetFallbackTextureForCharacter(char c) => getTextureForCharacter('?'); /// /// Whether the visual representation of a character should use fixed width when is true. diff --git a/osu.Framework/Graphics/Textures/TextureStore.cs b/osu.Framework/Graphics/Textures/TextureStore.cs index c1747bfe9..2cd630cc2 100644 --- a/osu.Framework/Graphics/Textures/TextureStore.cs +++ b/osu.Framework/Graphics/Textures/TextureStore.cs @@ -45,7 +45,8 @@ namespace osu.Framework.Graphics.Textures private Texture loadRaw(TextureUpload upload) { - if (upload == null || upload.Width > GLWrapper.MaxTextureSize || upload.Height > GLWrapper.MaxTextureSize) return null; + if (upload == null || upload.Width > GLWrapper.MaxTextureSize || upload.Height > GLWrapper.MaxTextureSize) + return null; var glTexture = atlas != null ? atlas.Add(upload.Width, upload.Height) : new TextureGLSingle(upload.Width, upload.Height, manualMipmaps, filteringMode); Texture tex = new Texture(glTexture) { ScaleAdjust = ScaleAdjust }; From a0c13e055c7d91bdcd83e85d7a8b965cfbbdf1d3 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Tue, 22 Jan 2019 18:20:00 +0900 Subject: [PATCH 05/16] Nuke whitespace again --- osu.Framework/Graphics/Textures/TextureStore.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/osu.Framework/Graphics/Textures/TextureStore.cs b/osu.Framework/Graphics/Textures/TextureStore.cs index 2cd630cc2..c1747bfe9 100644 --- a/osu.Framework/Graphics/Textures/TextureStore.cs +++ b/osu.Framework/Graphics/Textures/TextureStore.cs @@ -45,8 +45,7 @@ namespace osu.Framework.Graphics.Textures private Texture loadRaw(TextureUpload upload) { - if (upload == null || upload.Width > GLWrapper.MaxTextureSize || upload.Height > GLWrapper.MaxTextureSize) - return null; + if (upload == null || upload.Width > GLWrapper.MaxTextureSize || upload.Height > GLWrapper.MaxTextureSize) return null; var glTexture = atlas != null ? atlas.Add(upload.Width, upload.Height) : new TextureGLSingle(upload.Width, upload.Height, manualMipmaps, filteringMode); Texture tex = new Texture(glTexture) { ScaleAdjust = ScaleAdjust }; From 421c34b7cabed46787c31858f50adeafd91cd069 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Wed, 23 Jan 2019 12:13:34 +0900 Subject: [PATCH 06/16] Revert SpriteText changes --- osu.Framework/Graphics/Sprites/SpriteText.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/osu.Framework/Graphics/Sprites/SpriteText.cs b/osu.Framework/Graphics/Sprites/SpriteText.cs index 94698f0f0..a3d59ea15 100644 --- a/osu.Framework/Graphics/Sprites/SpriteText.cs +++ b/osu.Framework/Graphics/Sprites/SpriteText.cs @@ -587,14 +587,12 @@ namespace osu.Framework.Graphics.Sprites /// /// The character to get the texture for. /// The texture for the given character. - protected virtual Texture GetTextureForCharacter(char c) => getTextureForCharacter(c) ?? GetFallbackTextureForCharacter(c); - - private Texture getTextureForCharacter(char c) + protected virtual Texture GetTextureForCharacter(char c) { if (store == null) return null; - return store.GetCharacter(Font, c) ?? store.GetCharacter(null, c); + return store.GetCharacter(Font, c) ?? store.GetCharacter(null, c) ?? GetFallbackTextureForCharacter(c); } /// @@ -602,7 +600,7 @@ namespace osu.Framework.Graphics.Sprites /// /// The character which doesn't exist in the current font. /// The texture for the given character. - protected virtual Texture GetFallbackTextureForCharacter(char c) => getTextureForCharacter('?'); + protected virtual Texture GetFallbackTextureForCharacter(char c) => GetTextureForCharacter('?'); /// /// Whether the visual representation of a character should use fixed width when is true. From eaf8cc806fc1954ee1bb65b18497ca219e836df5 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Wed, 23 Jan 2019 12:36:11 +0900 Subject: [PATCH 07/16] Log an error if texture dimensions exceeds maximum allowable --- osu.Framework/Graphics/Textures/TextureStore.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/osu.Framework/Graphics/Textures/TextureStore.cs b/osu.Framework/Graphics/Textures/TextureStore.cs index c1747bfe9..d7dc15a6e 100644 --- a/osu.Framework/Graphics/Textures/TextureStore.cs +++ b/osu.Framework/Graphics/Textures/TextureStore.cs @@ -6,6 +6,7 @@ using osu.Framework.Graphics.OpenGL.Textures; using osu.Framework.IO.Stores; using System.Collections.Generic; using System.Threading.Tasks; +using osu.Framework.Logging; using osuTK.Graphics.ES30; namespace osu.Framework.Graphics.Textures @@ -45,7 +46,15 @@ namespace osu.Framework.Graphics.Textures private Texture loadRaw(TextureUpload upload) { - if (upload == null || upload.Width > GLWrapper.MaxTextureSize || upload.Height > GLWrapper.MaxTextureSize) return null; + if (upload == null) + return null; + + if (upload.Width > GLWrapper.MaxTextureSize || upload.Height > GLWrapper.MaxTextureSize) + { + Logger.Log("Texture dimensions exceeds the maximum allowable by the device!", level: LogLevel.Error); + return null; + } + var glTexture = atlas != null ? atlas.Add(upload.Width, upload.Height) : new TextureGLSingle(upload.Width, upload.Height, manualMipmaps, filteringMode); Texture tex = new Texture(glTexture) { ScaleAdjust = ScaleAdjust }; From 726986440e025bc401c3c7025d0862f8f10e55f3 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Wed, 23 Jan 2019 12:39:28 +0900 Subject: [PATCH 08/16] Trim whitespace --- osu.Framework/Graphics/Textures/TextureStore.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Framework/Graphics/Textures/TextureStore.cs b/osu.Framework/Graphics/Textures/TextureStore.cs index d7dc15a6e..903f7740a 100644 --- a/osu.Framework/Graphics/Textures/TextureStore.cs +++ b/osu.Framework/Graphics/Textures/TextureStore.cs @@ -54,7 +54,6 @@ namespace osu.Framework.Graphics.Textures Logger.Log("Texture dimensions exceeds the maximum allowable by the device!", level: LogLevel.Error); return null; } - var glTexture = atlas != null ? atlas.Add(upload.Width, upload.Height) : new TextureGLSingle(upload.Width, upload.Height, manualMipmaps, filteringMode); Texture tex = new Texture(glTexture) { ScaleAdjust = ScaleAdjust }; From f96a9fb840c050acd064bc78393b42a5984a15a8 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 23 Jan 2019 15:04:52 +0900 Subject: [PATCH 09/16] Add comment about default value --- osu.Framework/Graphics/OpenGL/GLWrapper.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Framework/Graphics/OpenGL/GLWrapper.cs b/osu.Framework/Graphics/OpenGL/GLWrapper.cs index f330a08a1..8022f34db 100644 --- a/osu.Framework/Graphics/OpenGL/GLWrapper.cs +++ b/osu.Framework/Graphics/OpenGL/GLWrapper.cs @@ -38,9 +38,9 @@ namespace osu.Framework.Graphics.OpenGL /// public static bool HasContext => GraphicsContext.CurrentContext != null; - public static int MaxTextureSize { get; private set; } = 4096; + public static int MaxTextureSize { get; private set; } = 4096; // default value is to allow roughly normal flow in cases we don't have a GL context, like headless CI. - private static readonly Scheduler reset_scheduler = new Scheduler(null); //force no thread set until we are actually on the draw thread. + private static readonly Scheduler reset_scheduler = new Scheduler(null); // force no thread set until we are actually on the draw thread. /// /// A queue from which a maximum of one operation is invoked per draw frame. From 6c732ca4ae4a7427e9ec0c0731470c45fc4594d9 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 23 Jan 2019 15:32:23 +0900 Subject: [PATCH 10/16] Move check and return name of failing load --- .../Graphics/Textures/TextureStore.cs | 19 +++++++++++-------- .../Graphics/Textures/TextureTooLargeForGL.cs | 11 +++++++++++ .../Graphics/Textures/TextureUpload.cs | 4 ++++ 3 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 osu.Framework/Graphics/Textures/TextureTooLargeForGL.cs diff --git a/osu.Framework/Graphics/Textures/TextureStore.cs b/osu.Framework/Graphics/Textures/TextureStore.cs index 903f7740a..6dd69490a 100644 --- a/osu.Framework/Graphics/Textures/TextureStore.cs +++ b/osu.Framework/Graphics/Textures/TextureStore.cs @@ -46,14 +46,8 @@ namespace osu.Framework.Graphics.Textures private Texture loadRaw(TextureUpload upload) { - if (upload == null) - return null; + if (upload == null) return null; - if (upload.Width > GLWrapper.MaxTextureSize || upload.Height > GLWrapper.MaxTextureSize) - { - Logger.Log("Texture dimensions exceeds the maximum allowable by the device!", level: LogLevel.Error); - return null; - } var glTexture = atlas != null ? atlas.Add(upload.Width, upload.Height) : new TextureGLSingle(upload.Width, upload.Height, manualMipmaps, filteringMode); Texture tex = new Texture(glTexture) { ScaleAdjust = ScaleAdjust }; @@ -77,7 +71,16 @@ namespace osu.Framework.Graphics.Textures { // refresh the texture if no longer available (may have been previously disposed). if (!textureCache.TryGetValue(name, out var tex) || tex?.Available == false) - textureCache[name] = tex = getTexture(name); + { + try + { + textureCache[name] = tex = getTexture(name); + } + catch (TextureTooLargeForGL) + { + Logger.Log($"Texture \"{name}\" exceeds the maximum size supported by this device ({GLWrapper.MaxTextureSize}px).", level: LogLevel.Error); + } + } return tex; } diff --git a/osu.Framework/Graphics/Textures/TextureTooLargeForGL.cs b/osu.Framework/Graphics/Textures/TextureTooLargeForGL.cs new file mode 100644 index 000000000..e80bc0ae3 --- /dev/null +++ b/osu.Framework/Graphics/Textures/TextureTooLargeForGL.cs @@ -0,0 +1,11 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE + +using System; + +namespace osu.Framework.Graphics.Textures +{ + public class TextureTooLargeForGL : InvalidOperationException + { + } +} diff --git a/osu.Framework/Graphics/Textures/TextureUpload.cs b/osu.Framework/Graphics/Textures/TextureUpload.cs index 3d194141e..aee6b6bc9 100644 --- a/osu.Framework/Graphics/Textures/TextureUpload.cs +++ b/osu.Framework/Graphics/Textures/TextureUpload.cs @@ -3,6 +3,7 @@ using System; using System.IO; +using osu.Framework.Graphics.OpenGL; using osu.Framework.Graphics.OpenGL.Buffers; using osu.Framework.Graphics.Primitives; using osuTK.Graphics.ES30; @@ -51,6 +52,9 @@ namespace osu.Framework.Graphics.Textures public TextureUpload(Image image) { this.image = image; + + if (image.Width > GLWrapper.MaxTextureSize || image.Height > GLWrapper.MaxTextureSize) + throw new TextureTooLargeForGL(); } /// From d94443555bd32c19ea6734cf8a278cb89c8ba20b Mon Sep 17 00:00:00 2001 From: David Zhao Date: Wed, 23 Jan 2019 17:22:44 +0900 Subject: [PATCH 11/16] Throw if texture being added to textureatlas is larger than the atlas itself --- osu.Framework/Graphics/Textures/TextureAtlas.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/osu.Framework/Graphics/Textures/TextureAtlas.cs b/osu.Framework/Graphics/Textures/TextureAtlas.cs index b85d8e632..4c95eba4b 100644 --- a/osu.Framework/Graphics/Textures/TextureAtlas.cs +++ b/osu.Framework/Graphics/Textures/TextureAtlas.cs @@ -3,6 +3,8 @@ using System; using System.Collections.Generic; +using System.Diagnostics; +using System.Reflection; using osu.Framework.Graphics.OpenGL.Textures; using osuTK.Graphics.ES30; using osu.Framework.Graphics.Sprites; @@ -107,6 +109,11 @@ namespace osu.Framework.Graphics.Textures { lock (textureRetrievalLock) { + if (width > atlasWidth || height > atlasHeight) + { + throw new InvalidOperationException($"Size of texture to be loaded exceeds the size of the texture atlas: {width}x{height}px."); + } + if (AtlasTexture == null) Reset(); From 186070f61e9ea1ab56870841c44f4cf6de1d448e Mon Sep 17 00:00:00 2001 From: David Zhao Date: Wed, 23 Jan 2019 17:23:05 +0900 Subject: [PATCH 12/16] Clean up --- osu.Framework/Graphics/Textures/TextureAtlas.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/osu.Framework/Graphics/Textures/TextureAtlas.cs b/osu.Framework/Graphics/Textures/TextureAtlas.cs index 4c95eba4b..98dc1f61a 100644 --- a/osu.Framework/Graphics/Textures/TextureAtlas.cs +++ b/osu.Framework/Graphics/Textures/TextureAtlas.cs @@ -3,8 +3,6 @@ using System; using System.Collections.Generic; -using System.Diagnostics; -using System.Reflection; using osu.Framework.Graphics.OpenGL.Textures; using osuTK.Graphics.ES30; using osu.Framework.Graphics.Sprites; @@ -110,9 +108,7 @@ namespace osu.Framework.Graphics.Textures lock (textureRetrievalLock) { if (width > atlasWidth || height > atlasHeight) - { throw new InvalidOperationException($"Size of texture to be loaded exceeds the size of the texture atlas: {width}x{height}px."); - } if (AtlasTexture == null) Reset(); From bcb6f3c30dca522bf8f2fa6e005184c142e647b4 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 23 Jan 2019 17:35:41 +0900 Subject: [PATCH 13/16] Update exception message to include actual size of texture atlas Co-Authored-By: nyquillerium --- osu.Framework/Graphics/Textures/TextureAtlas.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Framework/Graphics/Textures/TextureAtlas.cs b/osu.Framework/Graphics/Textures/TextureAtlas.cs index 98dc1f61a..95d2209e9 100644 --- a/osu.Framework/Graphics/Textures/TextureAtlas.cs +++ b/osu.Framework/Graphics/Textures/TextureAtlas.cs @@ -108,7 +108,7 @@ namespace osu.Framework.Graphics.Textures lock (textureRetrievalLock) { if (width > atlasWidth || height > atlasHeight) - throw new InvalidOperationException($"Size of texture to be loaded exceeds the size of the texture atlas: {width}x{height}px."); + throw new InvalidOperationException($"Size of allocation request ({width}x{height}) exceeds the maximum size of this {nameof(TextureAtlas)} ({atlasWidth}x{atlasHeight})."); if (AtlasTexture == null) Reset(); From a9e6ca7b0043a3c9c5e749917df31659c16ad303 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 23 Jan 2019 17:40:05 +0900 Subject: [PATCH 14/16] Move check outside of lock --- osu.Framework/Graphics/Textures/TextureAtlas.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Framework/Graphics/Textures/TextureAtlas.cs b/osu.Framework/Graphics/Textures/TextureAtlas.cs index 95d2209e9..bb2228005 100644 --- a/osu.Framework/Graphics/Textures/TextureAtlas.cs +++ b/osu.Framework/Graphics/Textures/TextureAtlas.cs @@ -105,11 +105,11 @@ namespace osu.Framework.Graphics.Textures internal TextureGL Add(int width, int height) { + if (width > atlasWidth || height > atlasHeight) + throw new InvalidOperationException($"Size of allocation request ({width}x{height}) exceeds the maximum size of this {nameof(TextureAtlas)} ({atlasWidth}x{atlasHeight})."); + lock (textureRetrievalLock) { - if (width > atlasWidth || height > atlasHeight) - throw new InvalidOperationException($"Size of allocation request ({width}x{height}) exceeds the maximum size of this {nameof(TextureAtlas)} ({atlasWidth}x{atlasHeight})."); - if (AtlasTexture == null) Reset(); From c66602044eb9553a1778cd3f42bd5aee76535387 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 23 Jan 2019 18:06:13 +0900 Subject: [PATCH 15/16] Use argument exceptions --- osu.Framework/Graphics/Textures/TextureAtlas.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/osu.Framework/Graphics/Textures/TextureAtlas.cs b/osu.Framework/Graphics/Textures/TextureAtlas.cs index bb2228005..32b5b7659 100644 --- a/osu.Framework/Graphics/Textures/TextureAtlas.cs +++ b/osu.Framework/Graphics/Textures/TextureAtlas.cs @@ -105,8 +105,11 @@ namespace osu.Framework.Graphics.Textures internal TextureGL Add(int width, int height) { - if (width > atlasWidth || height > atlasHeight) - throw new InvalidOperationException($"Size of allocation request ({width}x{height}) exceeds the maximum size of this {nameof(TextureAtlas)} ({atlasWidth}x{atlasHeight})."); + if (width > atlasWidth) + throw new ArgumentOutOfRangeException(nameof(width), width, $"Must be less than this atlas' width ({atlasWidth}px)."); + + if (height > atlasHeight) + throw new ArgumentOutOfRangeException(nameof(height), height, $"Must be less than this atlas' height ({atlasHeight}px)."); lock (textureRetrievalLock) { From 247c8733a807962de605fe735ff89a9edf463589 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 23 Jan 2019 18:50:27 +0900 Subject: [PATCH 16/16] Add exception suffix --- osu.Framework/Graphics/Textures/TextureStore.cs | 2 +- ...TextureTooLargeForGL.cs => TextureTooLargeForGLException.cs} | 2 +- osu.Framework/Graphics/Textures/TextureUpload.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename osu.Framework/Graphics/Textures/{TextureTooLargeForGL.cs => TextureTooLargeForGLException.cs} (75%) diff --git a/osu.Framework/Graphics/Textures/TextureStore.cs b/osu.Framework/Graphics/Textures/TextureStore.cs index 6dd69490a..6b4f579b1 100644 --- a/osu.Framework/Graphics/Textures/TextureStore.cs +++ b/osu.Framework/Graphics/Textures/TextureStore.cs @@ -76,7 +76,7 @@ namespace osu.Framework.Graphics.Textures { textureCache[name] = tex = getTexture(name); } - catch (TextureTooLargeForGL) + catch (TextureTooLargeForGLException) { Logger.Log($"Texture \"{name}\" exceeds the maximum size supported by this device ({GLWrapper.MaxTextureSize}px).", level: LogLevel.Error); } diff --git a/osu.Framework/Graphics/Textures/TextureTooLargeForGL.cs b/osu.Framework/Graphics/Textures/TextureTooLargeForGLException.cs similarity index 75% rename from osu.Framework/Graphics/Textures/TextureTooLargeForGL.cs rename to osu.Framework/Graphics/Textures/TextureTooLargeForGLException.cs index e80bc0ae3..297aabba9 100644 --- a/osu.Framework/Graphics/Textures/TextureTooLargeForGL.cs +++ b/osu.Framework/Graphics/Textures/TextureTooLargeForGLException.cs @@ -5,7 +5,7 @@ using System; namespace osu.Framework.Graphics.Textures { - public class TextureTooLargeForGL : InvalidOperationException + public class TextureTooLargeForGLException : InvalidOperationException { } } diff --git a/osu.Framework/Graphics/Textures/TextureUpload.cs b/osu.Framework/Graphics/Textures/TextureUpload.cs index aee6b6bc9..811731c2c 100644 --- a/osu.Framework/Graphics/Textures/TextureUpload.cs +++ b/osu.Framework/Graphics/Textures/TextureUpload.cs @@ -54,7 +54,7 @@ namespace osu.Framework.Graphics.Textures this.image = image; if (image.Width > GLWrapper.MaxTextureSize || image.Height > GLWrapper.MaxTextureSize) - throw new TextureTooLargeForGL(); + throw new TextureTooLargeForGLException(); } ///