From df412b6d339abe5c2d2595fb07fd5e7789c15da9 Mon Sep 17 00:00:00 2001 From: McSchneidar <262792195+McSchneidar@users.noreply.github.com> Date: Fri, 16 Oct 2026 05:53:10 +0200 Subject: [PATCH] Two small fixes (#904) * Fix index check in CSelectSlide.RenameValue The check used && instead of ||. An index cannot be negative and out of range at the same time, so the check never returned early and an invalid index caused an ArgumentOutOfRangeException. * Allow textures to be disposed more than once CTextureBase.Dispose threw ObjectDisposedException on a second call. Dispose must be safe to call multiple times, otherwise freeing a texture twice crashes the game. Return early instead. CD3DTexture and COGLTexture also check IsDisposed first, so a second call does not free the GPU texture again. This matters for OpenGL, where the texture name may already belong to another texture. --------- Co-authored-by: Florian Ostertag --- Vocaluxe/Lib/Draw/CDirect3D.cs | 5 +++++ Vocaluxe/Lib/Draw/COpenGL.cs | 5 +++++ Vocaluxe/Lib/Draw/CTextureBase.cs | 8 ++++---- VocaluxeLib/Menu/CSelectSlide.cs | 2 +- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 11cd69f4..0a7ace7c 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -65,6 +65,11 @@ namespace Vocaluxe.Lib.Draw public override void Dispose() { + if (IsDisposed) + { + return; + } + base.Dispose(); if (D3DTexture != null) { diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index f396d3b7..a84791ac 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -91,6 +91,11 @@ namespace Vocaluxe.Lib.Draw public override void Dispose() { + if (IsDisposed) + { + return; + } + base.Dispose(); if (Name != 0) { diff --git a/Vocaluxe/Lib/Draw/CTextureBase.cs b/Vocaluxe/Lib/Draw/CTextureBase.cs index 938b8544..b0ad146b 100644 --- a/Vocaluxe/Lib/Draw/CTextureBase.cs +++ b/Vocaluxe/Lib/Draw/CTextureBase.cs @@ -92,17 +92,17 @@ namespace Vocaluxe.Lib.Draw } } - private bool _IsDisposed; + protected bool IsDisposed { get; private set; } public virtual void Dispose() { - if (_IsDisposed) + if (IsDisposed) { - throw new ObjectDisposedException(GetType().Name); + return; } RefCount = 0; - _IsDisposed = true; + IsDisposed = true; } } } \ No newline at end of file diff --git a/VocaluxeLib/Menu/CSelectSlide.cs b/VocaluxeLib/Menu/CSelectSlide.cs index 5a5f0013..b97fe66e 100644 --- a/VocaluxeLib/Menu/CSelectSlide.cs +++ b/VocaluxeLib/Menu/CSelectSlide.cs @@ -389,7 +389,7 @@ namespace VocaluxeLib.Menu public void RenameValue(int index, string newName, CTextureRef newTexture = null) { - if (index < 0 && index >= _Values.Count) + if (index < 0 || index >= _Values.Count) { return; }