From 8b798fcaa7ae520842b1f1b091e39ece00cddeb0 Mon Sep 17 00:00:00 2001 From: homeburger Date: Sat, 23 May 2026 23:29:57 -0500 Subject: [PATCH] fix surface creation on linux --- src/Device.cpp | 7 ++++--- src/Window.cpp | 17 ++++++++++++----- src/Window.hpp | 2 +- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/Device.cpp b/src/Device.cpp index f3efab8..834bbc8 100644 --- a/src/Device.cpp +++ b/src/Device.cpp @@ -129,13 +129,14 @@ bool Device::createLogicalDevice() { break; } } - if(queueIndex == -1) { + if(queueIndex <= -1) { std::cout << "[" << __FUNCTION__ << ": " << __LINE__ << "] Error: could not locate valid graphics queues." << std::endl; + return false; } float queuePriority = 0.5f; vk::DeviceQueueCreateInfo deviceQueueCreateInfo { - .queueFamilyIndex = queueIndex, + .queueFamilyIndex = static_cast(queueIndex), .queueCount = 1, .pQueuePriorities = &queuePriority }; @@ -173,6 +174,6 @@ bool Device::createLogicalDevice() { void Device::createSurface() { - (void)window_->createSurface(&surface_); + (void)window_->createSurface(instance_, &surface_); } diff --git a/src/Window.cpp b/src/Window.cpp index 3636d14..b026b71 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -45,18 +45,25 @@ void Window::handleEvent(SDL_Event& event) { } } -bool Window::createSurface(vk::raii::SurfaceKHR* surface) { +bool Window::createSurface(vk::raii::Instance* instance, vk::raii::SurfaceKHR* surface) { - std::cout << "[" << __FUNCTION__ << ": " << __LINE__ << "] createSurface()" << std::endl; + if(instance == nullptr) { + std::cout << "[" << __FUNCTION__ << ": " << __LINE__ << "] Error: cannot create surface with a null Vulkan instance." << std::endl; + return false; + } #ifdef __WIN32 vk::Win32SurfaceCreateInfoKHR createInfo { .hinstance = GetModuleHandle(nullptr), .hwnd = (HWND)SDL_GetPointerProperty(SDL_GetWindowProperties(sdlWindow_), "SDL.window.win32.hwnd", nullptr); } - surface = &instance_.createWin32SurfaceKHR(createInfo); -#else // __WIN32 - + surface = instance->createWin32SurfaceKHR(createInfo); +#else + // this is so unbelievably ugly im so sorry + // its just sdl3 uses the c vulkan api and the app uses the c++ api + VkSurfaceKHR cSurface; + (void)SDL_Vulkan_CreateSurface(sdlWindow_, static_cast(**instance), nullptr, &cSurface); + *surface = vk::raii::SurfaceKHR(*instance, cSurface); #endif // __WIN32 std::cout << "[" << __FUNCTION__ << ": " << __LINE__ << "] attempted to createSurface" << std::endl; diff --git a/src/Window.hpp b/src/Window.hpp index 47badf2..1f85a98 100644 --- a/src/Window.hpp +++ b/src/Window.hpp @@ -18,7 +18,7 @@ public: bool rendering() { return rendering_; } bool open() { return open_; } - bool createSurface(vk::raii::SurfaceKHR* surface); + bool createSurface(vk::raii::Instance* instance, vk::raii::SurfaceKHR* surface); private: