From 7cb096177622a95bdbdda862bf7c089d6af5aa22 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Sun, 16 Mar 2025 19:15:15 +0100 Subject: [PATCH] Added some extra safety checks --- FSR2UnityPlugin.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/FSR2UnityPlugin.cpp b/FSR2UnityPlugin.cpp index 0a3dfe7..8e02a68 100644 --- a/FSR2UnityPlugin.cpp +++ b/FSR2UnityPlugin.cpp @@ -160,6 +160,11 @@ static uint32_t AllocateFeatureSlot() static void FreeFeatureSlot(uint32_t featureSlot) { + // Prevent duplicate free slots + auto& slots = s_FeatureSlots._Get_container(); + if (std::find(slots.begin(), slots.end(), featureSlot) != slots.end()) + return; + s_FeatureSlots.push(featureSlot); memset(&s_Features[featureSlot], 0, sizeof(FSR2Feature)); } @@ -221,6 +226,8 @@ extern "C" bool UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API AMDUP_InitApi() static void DestroyFeature(uint32_t featureSlot) { auto& feature = s_Features[featureSlot]; + if (!feature.isValid) + return; if (s_GraphicsD3D12 != nullptr) { @@ -244,11 +251,8 @@ static void DestroyFeature(uint32_t featureSlot) } } - if (feature.isValid) - { - ffxFsr2ContextDestroy(&feature.upscalingContext); - FreeFeatureSlot(featureSlot); - } + ffxFsr2ContextDestroy(&feature.upscalingContext); + FreeFeatureSlot(featureSlot); } extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API AMDUP_ShutdownApi()