Skip to content

Commit

Permalink
vulkan: fix a crash in setCanvas.
Browse files Browse the repository at this point in the history
  • Loading branch information
slime73 committed Jun 23, 2024
1 parent f548430 commit 10c435c
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/modules/graphics/vulkan/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1370,7 +1370,8 @@ void Graphics::startRecordingGraphicsCommands()
}
}

void Graphics::endRecordingGraphicsCommands() {
void Graphics::endRecordingGraphicsCommands()
{
if (renderPassState.active)
endRenderPass();

Expand Down Expand Up @@ -2426,8 +2427,28 @@ void Graphics::setDefaultRenderPass()
renderPassState.renderPassConfiguration = std::move(renderPassConfiguration);
renderPassState.framebufferConfiguration = std::move(framebufferConfiguration);

// Can't call clear() here because it depends on current RT state, which might not be
// set yet when this is called from within setRenderTargetsInternal.
if (renderPassState.windowClearRequested)
clear(renderPassState.mainWindowClearColorValue, renderPassState.mainWindowClearStencilValue, renderPassState.mainWindowClearDepthValue);
{
if (renderPassState.mainWindowClearColorValue.hasValue)
{
renderPassState.renderPassConfiguration.colorAttachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
renderPassState.clearColors[0].color = Texture::getClearColor(nullptr, renderPassState.mainWindowClearColorValue.value);
}

if (renderPassState.mainWindowClearDepthValue.hasValue && backbufferHasDepth)
{
renderPassState.renderPassConfiguration.staticData.depthStencilAttachment.depthLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
renderPassState.clearColors[1].depthStencil.depth = static_cast<float>(renderPassState.mainWindowClearDepthValue.value);
}

if (renderPassState.mainWindowClearStencilValue.hasValue && backbufferHasStencil)
{
renderPassState.renderPassConfiguration.staticData.depthStencilAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
renderPassState.clearColors[1].depthStencil.stencil = static_cast<uint32_t>(renderPassState.mainWindowClearStencilValue.value);
}
}
}

void Graphics::setRenderPass(const RenderTargets &rts, int pixelw, int pixelh, bool hasSRGBtexture)
Expand Down

0 comments on commit 10c435c

Please sign in to comment.