From 58207685c0dcda07d18f5f538629c775e2a714b8 Mon Sep 17 00:00:00 2001 From: jhorv <38920027+jhorv@users.noreply.github.com> Date: Sat, 25 Feb 2023 05:26:39 -0500 Subject: [PATCH] Perform bounds checking before list indexer to avoid frequent exceptions (#4438) * Perform bounds checking before list indexer to avoid frequent ArgumentOutOfRangeExceptions * do a single compare after casting id and .Count to uint --- Ryujinx.Graphics.Vulkan/IdList.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Ryujinx.Graphics.Vulkan/IdList.cs b/Ryujinx.Graphics.Vulkan/IdList.cs index d5a87a05..5c0623c3 100644 --- a/Ryujinx.Graphics.Vulkan/IdList.cs +++ b/Ryujinx.Graphics.Vulkan/IdList.cs @@ -80,8 +80,16 @@ namespace Ryujinx.Graphics.Vulkan try { - value = _list[id]; - return value != null; + if ((uint)id < (uint)_list.Count) + { + value = _list[id]; + return value != null; + } + else + { + value = null; + return false; + } } catch (ArgumentOutOfRangeException) {