diff --git a/src/app/service_based_app.cpp b/src/app/service_based_app.cpp index 31818b3..049f49d 100644 --- a/src/app/service_based_app.cpp +++ b/src/app/service_based_app.cpp @@ -39,11 +39,14 @@ namespace sdl3cpp::app { -ServiceBasedApp::ServiceBasedApp(services::RuntimeConfig runtimeConfig) +ServiceBasedApp::ServiceBasedApp(services::RuntimeConfig runtimeConfig, services::LogLevel logLevel) : runtimeConfig_(std::move(runtimeConfig)) { // Register logger service first registry_.RegisterService(); logger_ = registry_.GetService(); + if (logger_) { + logger_->SetLevel(logLevel); + } logger_->Trace("ServiceBasedApp", "ServiceBasedApp", "scriptPath=" + runtimeConfig_.scriptPath.string(), "constructor starting"); diff --git a/src/app/service_based_app.hpp b/src/app/service_based_app.hpp index fed6fbf..aee69b3 100644 --- a/src/app/service_based_app.hpp +++ b/src/app/service_based_app.hpp @@ -20,7 +20,7 @@ namespace sdl3cpp::app { */ class ServiceBasedApp : public services::IApplicationService { public: - explicit ServiceBasedApp(services::RuntimeConfig runtimeConfig); + explicit ServiceBasedApp(services::RuntimeConfig runtimeConfig, services::LogLevel logLevel); ~ServiceBasedApp(); ServiceBasedApp(const ServiceBasedApp&) = delete; diff --git a/src/main.cpp b/src/main.cpp index 4c490b2..240f8ae 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -46,11 +46,10 @@ int main(int argc, char** argv) { sdl3cpp::services::impl::CommandLineService commandLineService(startupLogger, platformService); sdl3cpp::services::CommandLineOptions options = commandLineService.Parse(argc, argv); - sdl3cpp::app::ServiceBasedApp app(options.runtimeConfig); - sdl3cpp::services::LogLevel logLevel = options.traceEnabled ? sdl3cpp::services::LogLevel::TRACE : sdl3cpp::services::LogLevel::INFO; + sdl3cpp::app::ServiceBasedApp app(options.runtimeConfig, logLevel); app.ConfigureLogging(logLevel, true, "sdl3_app.log"); auto logger = app.GetLogger(); diff --git a/src/services/impl/sdl_window_service.cpp b/src/services/impl/sdl_window_service.cpp index 79515e5..b98a14e 100644 --- a/src/services/impl/sdl_window_service.cpp +++ b/src/services/impl/sdl_window_service.cpp @@ -116,23 +116,31 @@ 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) { + // Ensure SDL video is initialized even if another subsystem (like audio) was started first. + const uint32_t initialized = SDL_WasInit(0); + const bool videoInitialized = (initialized & SDL_INIT_VIDEO) != 0; + if (!videoInitialized) { try { - ThrowSdlErrorIfFailed(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO), "SDL_Init failed", platformService_); + if (initialized == 0) { + ThrowSdlErrorIfFailed(SDL_Init(SDL_INIT_VIDEO), "SDL_Init(SDL_INIT_VIDEO) failed", platformService_); + } else { + ThrowSdlErrorIfFailed(SDL_InitSubSystem(SDL_INIT_VIDEO), + "SDL_InitSubSystem(SDL_INIT_VIDEO) failed", + platformService_); + } } catch (const std::exception& e) { ShowErrorDialog("SDL Initialization Failed", - std::string("Failed to initialize SDL subsystems.\n\nError: ") + e.what()); + std::string("Failed to initialize SDL video subsystem.\n\nError: ") + e.what()); throw; } + } - try { - ThrowSdlErrorIfFailed(SDL_Vulkan_LoadLibrary(nullptr), "SDL_Vulkan_LoadLibrary failed", platformService_); - } 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; - } + try { + ThrowSdlErrorIfFailed(SDL_Vulkan_LoadLibrary(nullptr), "SDL_Vulkan_LoadLibrary failed", platformService_); + } 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;