Skip to content

Commit fb7a5c2

Browse files
committed
Refactor drawFrame error handling to simplify main loop and address ErrorOutOfDateKHR with swapchain recreation.
1 parent f474f04 commit fb7a5c2

1 file changed

Lines changed: 3 additions & 16 deletions

File tree

attachments/17_swap_chain_recreation.cpp

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,7 @@ class HelloTriangleApplication {
113113
void mainLoop() {
114114
while (!glfwWindowShouldClose(window)) {
115115
glfwPollEvents();
116-
try {
117-
drawFrame();
118-
} catch (const vk::SystemError& e) {
119-
if (e.code().value() == static_cast<int>(vk::Result::eErrorOutOfDateKHR)) {
120-
// Swapchain is out of date, this can happen during window close
121-
// Just ignore and continue to close
122-
std::cout << "Ignoring ErrorOutOfDateKHR during shutdown" << std::endl;
123-
} else {
124-
// Rethrow other errors
125-
throw;
126-
}
127-
}
116+
drawFrame();
128117
}
129118

130119
device.waitIdle();
@@ -537,11 +526,9 @@ class HelloTriangleApplication {
537526
}
538527
} catch (const vk::SystemError& e) {
539528
if (e.code().value() == static_cast<int>(vk::Result::eErrorOutOfDateKHR)) {
540-
// Swapchain is out of date, this can happen during window close
541-
// Just ignore and continue to close
542-
std::cout << "Ignoring ErrorOutOfDateKHR during presentation" << std::endl;
529+
recreateSwapChain();
530+
return;
543531
} else {
544-
// Rethrow other errors
545532
throw;
546533
}
547534
}

0 commit comments

Comments
 (0)