Got the debug stuff in but we're not cleaning it up properly currently.

This commit is contained in:
Warwick New 2024-10-12 22:41:11 +01:00
parent 6d5854d5b1
commit 3deda81b1d

View file

@ -92,7 +92,6 @@ void populateDebugMessengerCreateInfo(
createInfo->pUserData = NULL; // Optional createInfo->pUserData = NULL; // Optional
} }
void createInstance(Application *app) { void createInstance(Application *app) {
if (enableValidationLayers && !checkValidationLayerSupport()) { if (enableValidationLayers && !checkValidationLayerSupport()) {
fprintf(stderr, "Validation layers requested, but not available!\n"); fprintf(stderr, "Validation layers requested, but not available!\n");
@ -191,30 +190,32 @@ VkResult CreateDebugUtilsMessengerEXT(
} }
void setupDebugMessenger(Application *app) { void setupDebugMessenger(Application *app) {
if (enableValidationLayers && !checkValidationLayerSupport()) {
fprintf(stderr, "Validation layers requested, but not available!\n");
exit(EXIT_FAILURE);
VkDebugUtilsMessengerCreateInfoEXT createInfo = {}; VkDebugUtilsMessengerCreateInfoEXT createInfo = {};
populateDebugMessengerCreateInfo(&createInfo); populateDebugMessengerCreateInfo(&createInfo);
if (CreateDebugUtilsMessengerEXT(app->instance, &createInfo, NULL, if (CreateDebugUtilsMessengerEXT(app->instance, &createInfo, NULL,
&app->debugMessenger) != VK_SUCCESS) { &app->debugMessenger) != VK_SUCCESS) {
fprintf(stderr, "failed to set up debug messenger!"); fprintf(stderr, "failed to set up debug messenger!\n");
}
} }
} }
void DestroyDebugUtilsMessengerEXT(VkInstance instance, void DestroyDebugUtilsMessengerEXT(VkInstance instance,
VkDebugUtilsMessengerEXT debugMessenger, VkDebugUtilsMessengerEXT *debugMessenger,
const VkAllocationCallbacks *pAllocator) { const VkAllocationCallbacks *pAllocator) {
PFN_vkDestroyDebugUtilsMessengerEXT func = PFN_vkDestroyDebugUtilsMessengerEXT func =
(PFN_vkDestroyDebugUtilsMessengerEXT)vkGetInstanceProcAddr( (PFN_vkDestroyDebugUtilsMessengerEXT)vkGetInstanceProcAddr(
instance, "vkDestroyDebugUtilsMessengerEXT"); instance, "vkDestroyDebugUtilsMessengerEXT");
if (func != NULL) { if (func != NULL) {
func(instance, debugMessenger, pAllocator); func(instance, *debugMessenger, pAllocator);
} }
} }
void initVulkan(Application *app) { void initVulkan(Application *app) {
if (enableValidationLayers) {
setupDebugMessenger(app); setupDebugMessenger(app);
}
createInstance(app); createInstance(app);
} }
void mainLoop(Application *app) { void mainLoop(Application *app) {
@ -224,7 +225,7 @@ void mainLoop(Application *app) {
} }
void cleanup(Application *app) { void cleanup(Application *app) {
if (enableValidationLayers) { if (enableValidationLayers) {
DestroyDebugUtilsMessengerEXT(app->instance, app->debugMessenger, NULL); DestroyDebugUtilsMessengerEXT(app->instance, &app->debugMessenger, NULL);
} }
vkDestroyInstance(app->instance, NULL); vkDestroyInstance(app->instance, NULL);
glfwDestroyWindow(app->window); glfwDestroyWindow(app->window);