mirror of
https://github.com/johndoe6345789/SDL3CPlusPlus.git
synced 2026-04-24 13:44:58 +00:00
feat: Add logging configuration to ServiceBasedApp and initialize SDL video subsystem correctly
This commit is contained in:
@@ -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<services::ILogger, services::impl::LoggerService>();
|
||||
logger_ = registry_.GetService<services::ILogger>();
|
||||
if (logger_) {
|
||||
logger_->SetLevel(logLevel);
|
||||
}
|
||||
|
||||
logger_->Trace("ServiceBasedApp", "ServiceBasedApp", "scriptPath=" + runtimeConfig_.scriptPath.string(), "constructor starting");
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user