Browse Source

Added some extra safety checks

fsr2
Nico de Poel 11 months ago
parent
commit
7cb0961776
  1. 14
      FSR2UnityPlugin.cpp

14
FSR2UnityPlugin.cpp

@ -160,6 +160,11 @@ static uint32_t AllocateFeatureSlot()
static void FreeFeatureSlot(uint32_t featureSlot) 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); s_FeatureSlots.push(featureSlot);
memset(&s_Features[featureSlot], 0, sizeof(FSR2Feature)); 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) static void DestroyFeature(uint32_t featureSlot)
{ {
auto& feature = s_Features[featureSlot]; auto& feature = s_Features[featureSlot];
if (!feature.isValid)
return;
if (s_GraphicsD3D12 != nullptr) 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() extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API AMDUP_ShutdownApi()

Loading…
Cancel
Save