fixed: handling window creation failure correctly

This commit is contained in:
2026-04-10 16:00:41 +02:00
parent e57149e9db
commit 7ff93e58ea
3 changed files with 10 additions and 7 deletions

View File

@@ -50,7 +50,11 @@ bool Application::Init() {
m_AppData.windowdata.eventCallback = [this](Event &event) { RaiseEvent(event); }; m_AppData.windowdata.eventCallback = [this](Event &event) { RaiseEvent(event); };
m_Window.push_back(std::make_shared<Window>(m_AppData.windowdata)); m_Window.push_back(std::make_shared<Window>(m_AppData.windowdata));
m_Window[0]->Create(); bool isSuccessful = m_Window[0]->Create();
if (!isSuccessful) {
Shutdown();
return false;
}
m_Renderer = SDL_CreateRenderer(GetSDLWindow(), nullptr); m_Renderer = SDL_CreateRenderer(GetSDLWindow(), nullptr);
if (!m_Renderer) { if (!m_Renderer) {

View File

@@ -12,8 +12,7 @@ namespace SakuraVNE {
Window::Window(const WindowData &data) : m_Data(data) {} Window::Window(const WindowData &data) : m_Data(data) {}
Window::~Window() { Destroy(); } Window::~Window() { Destroy(); }
void Window::Create(std::span<const SDL_WindowFlags> flags) { bool Window::Create(std::span<const SDL_WindowFlags> flags) {
// TODO: maybe get an unknow amount of parameters / an array of window flags? or just provide a seperate function for it
SDL_WindowFlags windowFlags = (SDL_WindowFlags)(SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY); SDL_WindowFlags windowFlags = (SDL_WindowFlags)(SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY);
for (auto &flag : flags) { for (auto &flag : flags) {
@@ -24,9 +23,7 @@ void Window::Create(std::span<const SDL_WindowFlags> flags) {
if (!m_Handle) { if (!m_Handle) {
LOG_ERROR("SDL window could not be created! {0}", SDL_GetError()); LOG_ERROR("SDL window could not be created! {0}", SDL_GetError());
// FIX: there has to be a better way to shutdown this cannot be correct, because i just quit the sdl stuff but the init continues return false;
Application::Get().Shutdown();
return;
} else { } else {
LOG_INFO("SDl window created"); LOG_INFO("SDl window created");
} }
@@ -40,6 +37,8 @@ void Window::Create(std::span<const SDL_WindowFlags> flags) {
} else { } else {
LOG_WARN("SDL window position not set. Will not attempt to set window position."); LOG_WARN("SDL window position not set. Will not attempt to set window position.");
} }
return true;
} }
void Window::ProcessEvent(const SDL_Event &event) { void Window::ProcessEvent(const SDL_Event &event) {

View File

@@ -26,7 +26,7 @@ public:
Window(const WindowData &data = WindowData()); Window(const WindowData &data = WindowData());
~Window(); ~Window();
void Create(std::span<const SDL_WindowFlags> flags = {}); bool Create(std::span<const SDL_WindowFlags> flags = {});
void Destroy(); void Destroy();
void Update(); void Update();