Skip to content

Fix incorrect handling of VkResult in swapchain creation#798

Open
DissolveDZ wants to merge 1 commit intoxCollateral:devfrom
DissolveDZ:patch-1
Open

Fix incorrect handling of VkResult in swapchain creation#798
DissolveDZ wants to merge 1 commit intoxCollateral:devfrom
DissolveDZ:patch-1

Conversation

@DissolveDZ
Copy link
Copy Markdown

@DissolveDZ DissolveDZ commented Apr 20, 2026

Hi,
I ran into some problems running this mod on my wayland linux setup and after some investigation it turned out the error handling of VkResult is incorrect.
Basically in Vulkan.java the checkResult function:

public static void checkResult(int result, String errorMessage) {
  if (result != VK_SUCCESS) {
    throw new RuntimeException(String.format("%s: %s", errorMessage, VkResult.decode(result)));
  }
}

should be changed to

public static void checkResult(int result, String errorMessage) {
  if (result < VK_SUCCESS) {  // Change to <
    throw new RuntimeException(String.format("%s: %s", errorMessage, VkResult.decode(result)));
   }
}

Fixes:
#791
#724
#708

This prevents fatal crashes on many linux setups. VkResult codes like VK_SUBOPTIMAL_KHR or VK_TIMEOUT should NOT be treated as fatal according to the vulkan spec.
Fatal errors return negative values, while non-fatal errors return positive values.
Ref:
https://docs.vulkan.org/refpages/latest/refpages/source/vkCreateSwapchainKHR.html
https://docs.vulkan.org/refpages/latest/refpages/source/VkResult.html

Tested on multiple setups, this is the correct behavior and "fixes" non-fatal errors being treated as crashes.
Errors like temporary out of date errors will resolve without crashing (e.g. resizing a window, losing window focus, etc.).

Fix incorrect handling of VkResult
@NotNekodev
Copy link
Copy Markdown
Contributor

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants