diff --git a/Ryujinx.Audio/Renderer/Server/Performance/PerformanceManagerGeneric.cs b/Ryujinx.Audio/Renderer/Server/Performance/PerformanceManagerGeneric.cs index b17e6f3f3a..4b8ec2546d 100644 --- a/Ryujinx.Audio/Renderer/Server/Performance/PerformanceManagerGeneric.cs +++ b/Ryujinx.Audio/Renderer/Server/Performance/PerformanceManagerGeneric.cs @@ -149,11 +149,21 @@ namespace Ryujinx.Audio.Renderer.Server.Performance Span targetSpan = performanceOutput.Slice(nextOffset); + // NOTE: We check for the space for two headers for the final blank header. + int requiredSpace = Unsafe.SizeOf() + Unsafe.SizeOf() * inputHeader.GetEntryCount() + + Unsafe.SizeOf() * inputHeader.GetEntryDetailCount() + + Unsafe.SizeOf(); + + if (targetSpan.Length < requiredSpace) + { + break; + } + ref THeader outputHeader = ref MemoryMarshal.Cast(targetSpan)[0]; nextOffset += Unsafe.SizeOf(); - Span outputEntries = MemoryMarshal.Cast(targetSpan.Slice(nextOffset)); + Span outputEntries = MemoryMarshal.Cast(performanceOutput.Slice(nextOffset)); int totalProcessingTime = 0; @@ -175,7 +185,7 @@ namespace Ryujinx.Audio.Renderer.Server.Performance } } - Span outputEntriesDetail = MemoryMarshal.Cast(targetSpan.Slice(nextOffset)); + Span outputEntriesDetail = MemoryMarshal.Cast(performanceOutput.Slice(nextOffset)); int effectiveEntryDetailCount = 0;