From fc9768f859566caa7091bdc658b924c257457490 Mon Sep 17 00:00:00 2001 From: Warwick New Date: Tue, 31 Dec 2024 12:59:54 +0000 Subject: [PATCH] Got the program to run and almost run without leaks --- CMakeLists.txt | 20 ++++++++++---------- src/main.c | 14 +++++++++----- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9dbe85e..32d6744 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,16 +30,16 @@ file(GLOB_RECURSE HEADER_FILES ${CMAKE_SOURCE_DIR}/src/*.h) add_executable(${PROJECT_NAME} ${HEADER_FILES} ${SOURCE_FILES}) -## Error on memory address issues in debug mode -#if(CMAKE_BUILD_TYPE MATCHES "Debug") -# set( -# CMAKE_C_FLAGS -# "${CMAKE_C_FLAGS} -Werror -fsanitize=undefined -fsanitize=address" -# ) -# target_link_options(${PROJECT_NAME} -# BEFORE PUBLIC -fsanitize=undefined PUBLIC -fsanitize=address -# ) -#endif() +# Error on memory address issues in debug mode +if(CMAKE_BUILD_TYPE MATCHES "Debug") + set( + CMAKE_C_FLAGS + "${CMAKE_C_FLAGS} -Werror -fsanitize=undefined -fsanitize=address" + ) + target_link_options(${PROJECT_NAME} + BEFORE PUBLIC -fsanitize=undefined PUBLIC -fsanitize=address + ) +endif() # Link Libraries target_link_libraries(${PROJECT_NAME} diff --git a/src/main.c b/src/main.c index 09908bb..ad51a50 100644 --- a/src/main.c +++ b/src/main.c @@ -183,16 +183,17 @@ void createInstance(Application *app) { } } + // This currently leaks memory :( VkResult result = vkCreateInstance(&createInfo, NULL, &app->instance); if (result != VK_SUCCESS) { fprintf(stderr, "Failed to create vulkan instance\n"); exit(EXIT_FAILURE); } - printf("Instance Extentions Available:\n"); - for (uint i = 0; i < extensionCount; i++) { - printf("\t%s\n", extensions[i].extensionName); - } + //printf("Instance Extentions Available:\n"); + //for (uint i = 0; i < extensionCount; i++) { + // printf("\t%s\n", extensions[i].extensionName); + //} } void initWindow(Application *app) { @@ -334,7 +335,7 @@ SwapChainSupportDetails querySwapchainSupport(VkPhysicalDevice device, &details.numPresentModes, NULL); if (details.numPresentModes > 0) { details.presentModes = - malloc(details.numFormats * sizeof(VkPresentModeKHR)); + malloc(details.numPresentModes * sizeof(VkPresentModeKHR)); vkGetPhysicalDeviceSurfacePresentModesKHR( device, *surface, &details.numPresentModes, details.presentModes); } @@ -578,6 +579,9 @@ void createSwapChain(Application *app) { app->swapChainImageFormat = surfaceFormat.format; app->swapChainExtent = extent; + + free(swapChainSupport.presentModes); + free(swapChainSupport.formats); } void createImageViews(Application *app) {