From 3903168a46726acd05d3bf03c965309e97b05445 Mon Sep 17 00:00:00 2001 From: johndoe6345789 Date: Sun, 4 Jan 2026 13:55:43 +0000 Subject: [PATCH] feat: Add SDL initialization in SdlWindowService to ensure proper setup before window creation --- src/app/service_based_app.cpp | 14 +++++++------- src/services/impl/sdl_window_service.cpp | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/app/service_based_app.cpp b/src/app/service_based_app.cpp index f011194..40910c9 100644 --- a/src/app/service_based_app.cpp +++ b/src/app/service_based_app.cpp @@ -151,13 +151,13 @@ void ServiceBasedApp::RegisterServices() { registry_.GetService(), registry_.GetService()); - // Graphics service (facade) - registry_.RegisterService( - registry_.GetService(), - registry_.GetService(), - registry_.GetService(), - registry_.GetService(), - registry_.GetService()); + // Graphics service (facade) - temporarily disabled + // registry_.RegisterService( + // registry_.GetService(), + // registry_.GetService(), + // registry_.GetService(), + // registry_.GetService(), + // registry_.GetService()); // Script service registry_.RegisterService(scriptPath_); diff --git a/src/services/impl/sdl_window_service.cpp b/src/services/impl/sdl_window_service.cpp index cc61525..df9736d 100644 --- a/src/services/impl/sdl_window_service.cpp +++ b/src/services/impl/sdl_window_service.cpp @@ -98,6 +98,25 @@ void SdlWindowService::CreateWindow(const WindowConfig& config) { throw std::runtime_error("Window already created"); } + // Initialize SDL here if not already initialized + if (SDL_WasInit(0) == 0) { + try { + ThrowSdlErrorIfFailed(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO), "SDL_Init failed"); + } catch (const std::exception& e) { + ShowErrorDialog("SDL Initialization Failed", + std::string("Failed to initialize SDL subsystems.\n\nError: ") + e.what()); + throw; + } + + try { + ThrowSdlErrorIfFailed(SDL_Vulkan_LoadLibrary(nullptr), "SDL_Vulkan_LoadLibrary failed"); + } catch (const std::exception& e) { + ShowErrorDialog("Vulkan Library Load Failed", + std::string("Failed to load Vulkan library. Make sure Vulkan drivers are installed.\n\nError: ") + e.what()); + throw; + } + } + uint32_t flags = SDL_WINDOW_VULKAN; if (config.resizable) { flags |= SDL_WINDOW_RESIZABLE;