fix: CaptureFrame no longer overwrites CapturedFrame with null

Root cause: CaptureFrame returned null and was assigned to CapturedFrame,
overwriting the data that ReadCapturedBuffer had just set at the start
of the same frame.

Fix: CaptureFrame is now void — only records GPU copy commands.
ReadCapturedBuffer runs at start of next frame (after WaitFrame/fence)
and sets CapturedFrame with actual pixel data.
Program.cs reads CapturedFrame after RenderWorld — now contains data
from the previous frame's GPU copy.
This commit is contained in:
emil28092005
2026-06-19 09:04:03 +03:00
parent 00b6f39201
commit b41e64db4a
2 changed files with 2 additions and 4 deletions
Binary file not shown.
+2 -4
View File
@@ -100,7 +100,7 @@ public sealed unsafe class VulkanRenderer : IRenderer, Engine.Graphics.IScreensh
Vk.vkBindBufferMemory(_ctx.Device, _screenshotBuffer, _screenshotMemory, 0);
}
public byte[]? CaptureFrame(VkCommandBuffer cmd, uint imageIndex)
public void CaptureFrame(VkCommandBuffer cmd, uint imageIndex)
{
InitScreenshotBuffer();
@@ -136,8 +136,6 @@ public sealed unsafe class VulkanRenderer : IRenderer, Engine.Graphics.IScreensh
TransitionImageLayout(cmd, _swapchain.Images[imageIndex],
VkImageLayout.TransferSrcOptimal, VkImageLayout.ColorAttachmentOptimal,
0x10000, 0x1000, 0x400, 0x100);
return null; // Data will be read next frame after GPU completes
}
private byte[]? ReadCapturedBuffer()
@@ -525,7 +523,7 @@ public sealed unsafe class VulkanRenderer : IRenderer, Engine.Graphics.IScreensh
// Capture frame AFTER render pass ends, BEFORE present transition
if (IsRecording)
{
CapturedFrame = CaptureFrame(cmd, imageIndex);
CaptureFrame(cmd, imageIndex); // Only records GPU commands, does NOT overwrite CapturedFrame
}
TransitionImageLayout(cmd, _swapchain.Images[imageIndex],