From 2fef371397cb09151b2e026e007e4103b7043aa3 Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Sun, 12 Nov 2023 12:03:25 +0100 Subject: [PATCH] Texture2D - Added texture slot clamping and debug assertion when slot is out of range --- PCK-Studio/Rendering/Texture2D.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/PCK-Studio/Rendering/Texture2D.cs b/PCK-Studio/Rendering/Texture2D.cs index ed4aa8cc..0112d9e8 100644 --- a/PCK-Studio/Rendering/Texture2D.cs +++ b/PCK-Studio/Rendering/Texture2D.cs @@ -1,11 +1,8 @@ using System; -using System.Collections.Generic; using System.Diagnostics; using System.Drawing; using System.Drawing.Imaging; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using OpenTK; using OpenTK.Graphics.OpenGL; namespace PckStudio.Rendering @@ -47,6 +44,8 @@ namespace PckStudio.Rendering public void Bind(int slot) { + Debug.Assert(slot >= 0 || slot < 32, "Slot is out of range"); + slot = MathHelper.Clamp(slot, 0, 31); GL.ActiveTexture(TextureUnit.Texture0 + slot); GL.BindTexture(TextureTarget.Texture2D, _id); }