From db05345cde73e892249183b9267799f770bff00a Mon Sep 17 00:00:00 2001 From: ParantezTech <12572227+par274@users.noreply.github.com> Date: Tue, 6 Oct 2026 17:47:34 +0300 Subject: [PATCH] [VideoOut] Unregister buffers after pending command streams Co-authored-by: Sekai <140012992+igettingit@users.noreply.github.com> --- src/SharpEmu.Libs/VideoOut/VideoOutExports.cs | 44 +++++++++++-------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/src/SharpEmu.Libs/VideoOut/VideoOutExports.cs b/src/SharpEmu.Libs/VideoOut/VideoOutExports.cs index a61e933..2688f09 100644 --- a/src/SharpEmu.Libs/VideoOut/VideoOutExports.cs +++ b/src/SharpEmu.Libs/VideoOut/VideoOutExports.cs @@ -1249,36 +1249,42 @@ public static partial class VideoOutExports { var handle = unchecked((int)ctx[CpuRegister.Rdi]); var attributeIndex = unchecked((int)ctx[CpuRegister.Rsi]); - if (!TryGetPort(handle, out var port)) - { - return OrbisVideoOutErrorInvalidHandle; - } - if (attributeIndex < 0) { return OrbisVideoOutErrorInvalidValue; } - lock (_stateGate) + var result = (int)OrbisGen2Result.ORBIS_GEN2_OK; + GuestGpu.Current.RunAfterPendingCommandStreams(() => { - if (attributeIndex >= port.Groups.Length || port.Groups[attributeIndex] is null) + lock (_stateGate) { - return OrbisVideoOutErrorInvalidValue; - } - - port.Groups[attributeIndex] = null; - foreach (var slot in port.BufferSlots) - { - if (slot.GroupIndex == attributeIndex) + if (!_ports.TryGetValue(handle, out var port)) { - slot.GroupIndex = -1; - slot.AddressLeft = 0; - slot.AddressRight = 0; + result = OrbisVideoOutErrorInvalidHandle; + return; + } + + if (attributeIndex >= port.Groups.Length || port.Groups[attributeIndex] is null) + { + result = OrbisVideoOutErrorInvalidValue; + return; + } + + port.Groups[attributeIndex] = null; + foreach (var slot in port.BufferSlots) + { + if (slot.GroupIndex == attributeIndex) + { + slot.GroupIndex = -1; + slot.AddressLeft = 0; + slot.AddressRight = 0; + } } } + }); - return (int)OrbisGen2Result.ORBIS_GEN2_OK; - } + return result; } [SysAbiExport(