Skip to content
Open
13 changes: 12 additions & 1 deletion attachments/15_hello_triangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,18 @@ class HelloTriangleApplication {
void mainLoop() {
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
drawFrame();
try {
drawFrame();
} catch (const vk::SystemError& e) {
if (e.code().value() == static_cast<int>(vk::Result::eErrorOutOfDateKHR)) {
// Swapchain is out of date, this can happen during window close
// Just ignore and continue to close
std::cout << "Ignoring ErrorOutOfDateKHR during shutdown" << std::endl;
} else {
// Rethrow other errors
throw;
}
}
}

device.waitIdle();
Expand Down
13 changes: 12 additions & 1 deletion attachments/16_frames_in_flight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,18 @@ class HelloTriangleApplication {
void mainLoop() {
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
drawFrame();
try {
drawFrame();
} catch (const vk::SystemError& e) {
if (e.code().value() == static_cast<int>(vk::Result::eErrorOutOfDateKHR)) {
// Swapchain is out of date, this can happen during window close
// Just ignore and continue to close
std::cout << "Ignoring ErrorOutOfDateKHR during shutdown" << std::endl;
} else {
// Rethrow other errors
throw;
}
}
}

device.waitIdle();
Expand Down
40 changes: 31 additions & 9 deletions attachments/17_swap_chain_recreation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,18 @@ class HelloTriangleApplication {
void mainLoop() {
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
drawFrame();
try {
drawFrame();
} catch (const vk::SystemError& e) {
if (e.code().value() == static_cast<int>(vk::Result::eErrorOutOfDateKHR)) {
// Swapchain is out of date, this can happen during window close
// Just ignore and continue to close
std::cout << "Ignoring ErrorOutOfDateKHR during shutdown" << std::endl;
} else {
// Rethrow other errors
throw;
}
}
}

device.waitIdle();
Expand Down Expand Up @@ -535,14 +546,25 @@ class HelloTriangleApplication {
graphicsQueue.submit(submitInfo, *inFlightFences[currentFrame]);


const vk::PresentInfoKHR presentInfoKHR{ .waitSemaphoreCount = 1, .pWaitSemaphores = &*renderFinishedSemaphore[imageIndex],
.swapchainCount = 1, .pSwapchains = &*swapChain, .pImageIndices = &imageIndex };
result = presentQueue.presentKHR( presentInfoKHR );
if (result == vk::Result::eErrorOutOfDateKHR || result == vk::Result::eSuboptimalKHR || framebufferResized) {
framebufferResized = false;
recreateSwapChain();
} else if (result != vk::Result::eSuccess) {
throw std::runtime_error("failed to present swap chain image!");
try {
const vk::PresentInfoKHR presentInfoKHR{ .waitSemaphoreCount = 1, .pWaitSemaphores = &*renderFinishedSemaphore[imageIndex],
.swapchainCount = 1, .pSwapchains = &*swapChain, .pImageIndices = &imageIndex };
result = presentQueue.presentKHR( presentInfoKHR );
if (result == vk::Result::eErrorOutOfDateKHR || result == vk::Result::eSuboptimalKHR || framebufferResized) {
framebufferResized = false;
recreateSwapChain();
} else if (result != vk::Result::eSuccess) {
throw std::runtime_error("failed to present swap chain image!");
}
} catch (const vk::SystemError& e) {
if (e.code().value() == static_cast<int>(vk::Result::eErrorOutOfDateKHR)) {
// Swapchain is out of date, this can happen during window close
// Just ignore and continue to close
std::cout << "Ignoring ErrorOutOfDateKHR during presentation" << std::endl;
} else {
// Rethrow other errors
throw;
}
}
semaphoreIndex = (semaphoreIndex + 1) % presentCompleteSemaphore.size();
currentFrame = (currentFrame + 1) % MAX_FRAMES_IN_FLIGHT;
Expand Down
40 changes: 31 additions & 9 deletions attachments/18_vertex_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,18 @@ class HelloTriangleApplication {
void mainLoop() {
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
drawFrame();
try {
drawFrame();
} catch (const vk::SystemError& e) {
if (e.code().value() == static_cast<int>(vk::Result::eErrorOutOfDateKHR)) {
// Swapchain is out of date, this can happen during window close
// Just ignore and continue to close
std::cout << "Ignoring ErrorOutOfDateKHR during shutdown" << std::endl;
} else {
// Rethrow other errors
throw;
}
}
}

device.waitIdle();
Expand Down Expand Up @@ -562,14 +573,25 @@ class HelloTriangleApplication {
graphicsQueue.submit(submitInfo, *inFlightFences[currentFrame]);


const vk::PresentInfoKHR presentInfoKHR{ .waitSemaphoreCount = 1, .pWaitSemaphores = &*renderFinishedSemaphore[imageIndex],
.swapchainCount = 1, .pSwapchains = &*swapChain, .pImageIndices = &imageIndex };
result = presentQueue.presentKHR( presentInfoKHR );
if (result == vk::Result::eErrorOutOfDateKHR || result == vk::Result::eSuboptimalKHR || framebufferResized) {
framebufferResized = false;
recreateSwapChain();
} else if (result != vk::Result::eSuccess) {
throw std::runtime_error("failed to present swap chain image!");
try {
const vk::PresentInfoKHR presentInfoKHR{ .waitSemaphoreCount = 1, .pWaitSemaphores = &*renderFinishedSemaphore[imageIndex],
.swapchainCount = 1, .pSwapchains = &*swapChain, .pImageIndices = &imageIndex };
result = presentQueue.presentKHR( presentInfoKHR );
if (result == vk::Result::eErrorOutOfDateKHR || result == vk::Result::eSuboptimalKHR || framebufferResized) {
framebufferResized = false;
recreateSwapChain();
} else if (result != vk::Result::eSuccess) {
throw std::runtime_error("failed to present swap chain image!");
}
} catch (const vk::SystemError& e) {
if (e.code().value() == static_cast<int>(vk::Result::eErrorOutOfDateKHR)) {
// Swapchain is out of date, this can happen during window close
// Just ignore and continue to close
std::cout << "Ignoring ErrorOutOfDateKHR during presentation" << std::endl;
} else {
// Rethrow other errors
throw;
}
}
semaphoreIndex = (semaphoreIndex + 1) % presentCompleteSemaphore.size();
currentFrame = (currentFrame + 1) % MAX_FRAMES_IN_FLIGHT;
Expand Down
40 changes: 31 additions & 9 deletions attachments/19_vertex_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,18 @@ class HelloTriangleApplication {
void mainLoop() {
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
drawFrame();
try {
drawFrame();
} catch (const vk::SystemError& e) {
if (e.code().value() == static_cast<int>(vk::Result::eErrorOutOfDateKHR)) {
// Swapchain is out of date, this can happen during window close
// Just ignore and continue to close
std::cout << "Ignoring ErrorOutOfDateKHR during shutdown" << std::endl;
} else {
// Rethrow other errors
throw;
}
}
}

device.waitIdle();
Expand Down Expand Up @@ -592,14 +603,25 @@ class HelloTriangleApplication {
graphicsQueue.submit(submitInfo, *inFlightFences[currentFrame]);


const vk::PresentInfoKHR presentInfoKHR{ .waitSemaphoreCount = 1, .pWaitSemaphores = &*renderFinishedSemaphore[imageIndex],
.swapchainCount = 1, .pSwapchains = &*swapChain, .pImageIndices = &imageIndex };
result = presentQueue.presentKHR( presentInfoKHR );
if (result == vk::Result::eErrorOutOfDateKHR || result == vk::Result::eSuboptimalKHR || framebufferResized) {
framebufferResized = false;
recreateSwapChain();
} else if (result != vk::Result::eSuccess) {
throw std::runtime_error("failed to present swap chain image!");
try {
const vk::PresentInfoKHR presentInfoKHR{ .waitSemaphoreCount = 1, .pWaitSemaphores = &*renderFinishedSemaphore[imageIndex],
.swapchainCount = 1, .pSwapchains = &*swapChain, .pImageIndices = &imageIndex };
result = presentQueue.presentKHR( presentInfoKHR );
if (result == vk::Result::eErrorOutOfDateKHR || result == vk::Result::eSuboptimalKHR || framebufferResized) {
framebufferResized = false;
recreateSwapChain();
} else if (result != vk::Result::eSuccess) {
throw std::runtime_error("failed to present swap chain image!");
}
} catch (const vk::SystemError& e) {
if (e.code().value() == static_cast<int>(vk::Result::eErrorOutOfDateKHR)) {
// Swapchain is out of date, this can happen during window close
// Just ignore and continue to close
std::cout << "Ignoring ErrorOutOfDateKHR during presentation" << std::endl;
} else {
// Rethrow other errors
throw;
}
}
semaphoreIndex = (semaphoreIndex + 1) % presentCompleteSemaphore.size();
currentFrame = (currentFrame + 1) % MAX_FRAMES_IN_FLIGHT;
Expand Down
40 changes: 31 additions & 9 deletions attachments/20_staging_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,18 @@ class HelloTriangleApplication {
void mainLoop() {
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
drawFrame();
try {
drawFrame();
} catch (const vk::SystemError& e) {
if (e.code().value() == static_cast<int>(vk::Result::eErrorOutOfDateKHR)) {
// Swapchain is out of date, this can happen during window close
// Just ignore and continue to close
std::cout << "Ignoring ErrorOutOfDateKHR during shutdown" << std::endl;
} else {
// Rethrow other errors
throw;
}
}
}

device.waitIdle();
Expand Down Expand Up @@ -611,14 +622,25 @@ class HelloTriangleApplication {
graphicsQueue.submit(submitInfo, *inFlightFences[currentFrame]);


const vk::PresentInfoKHR presentInfoKHR{ .waitSemaphoreCount = 1, .pWaitSemaphores = &*renderFinishedSemaphore[imageIndex],
.swapchainCount = 1, .pSwapchains = &*swapChain, .pImageIndices = &imageIndex };
result = presentQueue.presentKHR( presentInfoKHR );
if (result == vk::Result::eErrorOutOfDateKHR || result == vk::Result::eSuboptimalKHR || framebufferResized) {
framebufferResized = false;
recreateSwapChain();
} else if (result != vk::Result::eSuccess) {
throw std::runtime_error("failed to present swap chain image!");
try {
const vk::PresentInfoKHR presentInfoKHR{ .waitSemaphoreCount = 1, .pWaitSemaphores = &*renderFinishedSemaphore[imageIndex],
.swapchainCount = 1, .pSwapchains = &*swapChain, .pImageIndices = &imageIndex };
result = presentQueue.presentKHR( presentInfoKHR );
if (result == vk::Result::eErrorOutOfDateKHR || result == vk::Result::eSuboptimalKHR || framebufferResized) {
framebufferResized = false;
recreateSwapChain();
} else if (result != vk::Result::eSuccess) {
throw std::runtime_error("failed to present swap chain image!");
}
} catch (const vk::SystemError& e) {
if (e.code().value() == static_cast<int>(vk::Result::eErrorOutOfDateKHR)) {
// Swapchain is out of date, this can happen during window close
// Just ignore and continue to close
std::cout << "Ignoring ErrorOutOfDateKHR during presentation" << std::endl;
} else {
// Rethrow other errors
throw;
}
}
semaphoreIndex = (semaphoreIndex + 1) % presentCompleteSemaphore.size();
currentFrame = (currentFrame + 1) % MAX_FRAMES_IN_FLIGHT;
Expand Down
13 changes: 12 additions & 1 deletion attachments/21_index_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,18 @@ class HelloTriangleApplication {
void mainLoop() {
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
drawFrame();
try {
drawFrame();
} catch (const vk::SystemError& e) {
if (e.code().value() == static_cast<int>(vk::Result::eErrorOutOfDateKHR)) {
// Swapchain is out of date, this can happen during window close
// Just ignore and continue to close
std::cout << "Ignoring ErrorOutOfDateKHR during shutdown" << std::endl;
} else {
// Rethrow other errors
throw;
}
}
}

device.waitIdle();
Expand Down
13 changes: 12 additions & 1 deletion attachments/22_descriptor_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,18 @@ class HelloTriangleApplication {
void mainLoop() {
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
drawFrame();
try {
drawFrame();
} catch (const vk::SystemError& e) {
if (e.code().value() == static_cast<int>(vk::Result::eErrorOutOfDateKHR)) {
// Swapchain is out of date, this can happen during window close
// Just ignore and continue to close
std::cout << "Ignoring ErrorOutOfDateKHR during shutdown" << std::endl;
} else {
// Rethrow other errors
throw;
}
}
}

device.waitIdle();
Expand Down
13 changes: 12 additions & 1 deletion attachments/23_descriptor_sets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,18 @@ class HelloTriangleApplication {
void mainLoop() {
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
drawFrame();
try {
drawFrame();
} catch (const vk::SystemError& e) {
if (e.code().value() == static_cast<int>(vk::Result::eErrorOutOfDateKHR)) {
// Swapchain is out of date, this can happen during window close
// Just ignore and continue to close
std::cout << "Ignoring ErrorOutOfDateKHR during shutdown" << std::endl;
} else {
// Rethrow other errors
throw;
}
}
}

device.waitIdle();
Expand Down
13 changes: 12 additions & 1 deletion attachments/24_texture_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,18 @@ class HelloTriangleApplication {
void mainLoop() {
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
drawFrame();
try {
drawFrame();
} catch (const vk::SystemError& e) {
if (e.code().value() == static_cast<int>(vk::Result::eErrorOutOfDateKHR)) {
// Swapchain is out of date, this can happen during window close
// Just ignore and continue to close
std::cout << "Ignoring ErrorOutOfDateKHR during shutdown" << std::endl;
} else {
// Rethrow other errors
throw;
}
}
}

device.waitIdle();
Expand Down
13 changes: 12 additions & 1 deletion attachments/25_sampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,18 @@ class HelloTriangleApplication {
void mainLoop() {
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
drawFrame();
try {
drawFrame();
} catch (const vk::SystemError& e) {
if (e.code().value() == static_cast<int>(vk::Result::eErrorOutOfDateKHR)) {
// Swapchain is out of date, this can happen during window close
// Just ignore and continue to close
std::cout << "Ignoring ErrorOutOfDateKHR during shutdown" << std::endl;
} else {
// Rethrow other errors
throw;
}
}
}

device.waitIdle();
Expand Down
27 changes: 19 additions & 8 deletions attachments/26_texture_mapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -931,14 +931,25 @@ class HelloTriangleApplication {
graphicsQueue.submit(submitInfo, *inFlightFences[currentFrame]);


const vk::PresentInfoKHR presentInfoKHR{ .waitSemaphoreCount = 1, .pWaitSemaphores = &*renderFinishedSemaphore[imageIndex],
.swapchainCount = 1, .pSwapchains = &*swapChain, .pImageIndices = &imageIndex };
result = presentQueue.presentKHR(presentInfoKHR);
if (result == vk::Result::eErrorOutOfDateKHR || result == vk::Result::eSuboptimalKHR || framebufferResized) {
framebufferResized = false;
recreateSwapChain();
} else if (result != vk::Result::eSuccess) {
throw std::runtime_error("failed to present swap chain image!");
try {
const vk::PresentInfoKHR presentInfoKHR{ .waitSemaphoreCount = 1, .pWaitSemaphores = &*renderFinishedSemaphore[imageIndex],
.swapchainCount = 1, .pSwapchains = &*swapChain, .pImageIndices = &imageIndex };
result = presentQueue.presentKHR(presentInfoKHR);
if (result == vk::Result::eErrorOutOfDateKHR || result == vk::Result::eSuboptimalKHR || framebufferResized) {
framebufferResized = false;
recreateSwapChain();
} else if (result != vk::Result::eSuccess) {
throw std::runtime_error("failed to present swap chain image!");
}
} catch (const vk::SystemError& e) {
if (e.code().value() == static_cast<int>(vk::Result::eErrorOutOfDateKHR)) {
// Swapchain is out of date, this can happen during window close
// Just ignore and continue to close
std::cout << "Ignoring ErrorOutOfDateKHR during presentation" << std::endl;
} else {
// Rethrow other errors
throw;
}
}
semaphoreIndex = (semaphoreIndex + 1) % presentCompleteSemaphore.size();
currentFrame = (currentFrame + 1) % MAX_FRAMES_IN_FLIGHT;
Expand Down
Loading
Loading