love.window.setMode shows a popup if internal graphics initialization fails.

Related: #2335.
This commit is contained in:
Sasha Szpakowski
2026-07-18 10:57:13 -03:00
parent 57e8330a64
commit 8cd9cdd3ac
3 changed files with 13 additions and 16 deletions
+1 -1
View File
@@ -233,7 +233,7 @@ function love.errorhandler(msg)
success, status = pcall(love.window.setMode, 800, 600) success, status = pcall(love.window.setMode, 800, 600)
end end
if not success or not status then if not success or not status then
love.window.showMessageBox("Error during startup", msg, "error", false) love.window.showMessageBox("Initialization error", msg, "error", false)
return return
end end
end end
+12 -14
View File
@@ -84,7 +84,6 @@ Window::Window()
#ifdef LOVE_GRAPHICS_METAL #ifdef LOVE_GRAPHICS_METAL
, metalView(nullptr) , metalView(nullptr)
#endif #endif
, displayedWindowError(false)
, contextAttribs() , contextAttribs()
{ {
if (!SDL_InitSubSystem(SDL_INIT_VIDEO | SDL_INIT_EVENTS)) if (!SDL_InitSubSystem(SDL_INIT_VIDEO | SDL_INIT_EVENTS))
@@ -425,8 +424,7 @@ bool Window::createWindowAndContext(int x, int y, int w, int h, Uint32 windowfla
if (failed) if (failed)
{ {
std::string title = "Unable to create renderer"; std::string message = "This program requires a graphics card and video drivers which support Vulkan, OpenGL 3.3, or OpenGL ES 3.0.";
std::string message = "This program requires a graphics card and video drivers which support OpenGL 3.3 or OpenGL ES 3.0.";
if (!glversion.empty()) if (!glversion.empty())
message += "\n\nDetected OpenGL version:\n" + glversion; message += "\n\nDetected OpenGL version:\n" + glversion;
@@ -435,16 +433,9 @@ bool Window::createWindowAndContext(int x, int y, int w, int h, Uint32 windowfla
else if (!windowerror.empty()) else if (!windowerror.empty())
message += "\n\nSDL window creation error: " + windowerror; message += "\n\nSDL window creation error: " + windowerror;
std::cerr << title << std::endl << message << std::endl; close(false);
// Display a message box with the error, but only once. throw love::Exception("Unable to create renderer.\n%s", message.c_str());
if (!displayedWindowError)
{
showMessageBox(title, message, MESSAGEBOX_ERROR, false);
displayedWindowError = true;
}
close();
return false; return false;
} }
@@ -677,8 +668,15 @@ bool Window::setWindow(int width, int height, WindowSettings *settings)
context = (void *) SDL_Metal_GetLayer(metalView); context = (void *) SDL_Metal_GetLayer(metalView);
#endif #endif
// TODO: try/catch try
graphics->setMode(context, backbufferSettings); {
graphics->setMode(context, backbufferSettings);
}
catch (std::exception &e)
{
close(false);
throw love::Exception("Failed to initialize graphics.\n%s", e.what());
}
} }
else else
{ {
-1
View File
@@ -187,7 +187,6 @@ private:
graphics::Renderer windowRenderer = graphics::RENDERER_NONE; graphics::Renderer windowRenderer = graphics::RENDERER_NONE;
bool displayedWindowError;
ContextAttribs contextAttribs; ContextAttribs contextAttribs;
StrongRef<graphics::Graphics> graphics; StrongRef<graphics::Graphics> graphics;