mirror of
https://github.com/johndoe6345789/SDL3CPlusPlus.git
synced 2026-04-24 21:55:09 +00:00
feat: Add SDL initialization in SdlWindowService to ensure proper setup before window creation
This commit is contained in:
@@ -151,13 +151,13 @@ void ServiceBasedApp::RegisterServices() {
|
||||
registry_.GetService<services::IVulkanDeviceService>(),
|
||||
registry_.GetService<services::ISwapchainService>());
|
||||
|
||||
// Graphics service (facade)
|
||||
registry_.RegisterService<services::IGraphicsService, services::impl::GraphicsService>(
|
||||
registry_.GetService<services::IVulkanDeviceService>(),
|
||||
registry_.GetService<services::ISwapchainService>(),
|
||||
registry_.GetService<services::IPipelineService>(),
|
||||
registry_.GetService<services::IBufferService>(),
|
||||
registry_.GetService<services::IRenderCommandService>());
|
||||
// Graphics service (facade) - temporarily disabled
|
||||
// registry_.RegisterService<services::IGraphicsService, services::impl::GraphicsService>(
|
||||
// registry_.GetService<services::IVulkanDeviceService>(),
|
||||
// registry_.GetService<services::ISwapchainService>(),
|
||||
// registry_.GetService<services::IPipelineService>(),
|
||||
// registry_.GetService<services::IBufferService>(),
|
||||
// registry_.GetService<services::IRenderCommandService>());
|
||||
|
||||
// Script service
|
||||
registry_.RegisterService<services::IScriptService, services::impl::LuaScriptService>(scriptPath_);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user