From ceeb70a99612482befddb2606a8b2aceec361eb9 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Sat, 4 Sep 2021 01:43:52 -0300 Subject: [PATCH] TextureStorage should hold a ref of the foreign storage, otherwise it might be freed while in use --- Ryujinx.Graphics.Vulkan/TextureStorage.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Ryujinx.Graphics.Vulkan/TextureStorage.cs b/Ryujinx.Graphics.Vulkan/TextureStorage.cs index 7d1e749b2..c9d2d34f1 100644 --- a/Ryujinx.Graphics.Vulkan/TextureStorage.cs +++ b/Ryujinx.Graphics.Vulkan/TextureStorage.cs @@ -33,6 +33,7 @@ namespace Ryujinx.Graphics.Vulkan private readonly Image _image; private readonly Auto _imageAuto; private readonly Auto _allocationAuto; + private Auto _foreignAllocationAuto; private Dictionary _aliasedStorages; @@ -140,6 +141,8 @@ namespace Ryujinx.Graphics.Vulkan } else { + _foreignAllocationAuto = foreignAllocation; + foreignAllocation.IncrementReferenceCount(); var allocation = foreignAllocation.GetUnsafe(); gd.Api.BindImageMemory(device, _image, allocation.Memory, allocation.Offset).ThrowOnError(); @@ -277,6 +280,8 @@ namespace Ryujinx.Graphics.Vulkan _imageAuto.Dispose(); _allocationAuto?.Dispose(); + _foreignAllocationAuto?.DecrementReferenceCount(); + _foreignAllocationAuto = null; } } }