From b1a9d17cf85ab8322aeb700ad28d58f0edf63d08 Mon Sep 17 00:00:00 2001
From: gdkchan <gab.dark.100@gmail.com>
Date: Sat, 10 Jul 2021 16:50:10 -0300
Subject: [PATCH] Fix GetWritableRegion write-back (#2456)

---
 Ryujinx.Memory/IVirtualMemoryManager.cs | 4 +++-
 Ryujinx.Memory/MemoryBlock.cs           | 2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/Ryujinx.Memory/IVirtualMemoryManager.cs b/Ryujinx.Memory/IVirtualMemoryManager.cs
index b5e080199e..056940cc42 100644
--- a/Ryujinx.Memory/IVirtualMemoryManager.cs
+++ b/Ryujinx.Memory/IVirtualMemoryManager.cs
@@ -66,7 +66,9 @@ namespace Ryujinx.Memory
             {
                 int copySize = (int)Math.Min(MaxChunkSize, size - subOffset);
 
-                GetWritableRegion(va + subOffset, copySize).Memory.Span.Fill(0);
+                using var writableRegion = GetWritableRegion(va + subOffset, copySize);
+
+                writableRegion.Memory.Span.Fill(0);
             }
         }
 
diff --git a/Ryujinx.Memory/MemoryBlock.cs b/Ryujinx.Memory/MemoryBlock.cs
index e331a4537e..25c66dfe37 100644
--- a/Ryujinx.Memory/MemoryBlock.cs
+++ b/Ryujinx.Memory/MemoryBlock.cs
@@ -333,7 +333,7 @@ namespace Ryujinx.Memory
         /// <exception cref="InvalidMemoryRegionException">Throw when either <paramref name="offset"/> or <paramref name="size"/> are out of range</exception>
         public WritableRegion GetWritableRegion(ulong offset, int size)
         {
-            return new WritableRegion(this, offset, GetMemory(offset, size));
+            return new WritableRegion(null, offset, GetMemory(offset, size));
         }
 
         /// <summary>