Skip to content

Commit

Permalink
DisplayServer: Don't fallback to headless
Browse files Browse the repository at this point in the history
Unless users requested the headless driver specifically, they expect to either
see a window, or that the process terminates if there's an error.

Currently it would fallback to headless so they'd unexpectedly get a valid headless
instance if their DisplayServer failed initializing (e.g. missing Vulkan support).

Fixes godotengine#58414.
  • Loading branch information
akien-mga committed Jul 1, 2022
1 parent 692c2d9 commit 833c786
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1460,18 +1460,19 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
/* Determine audio and video drivers */

// Display driver, e.g. X11, Wayland.
// print_line("requested display driver : " + display_driver);
// Make sure that headless is the last one, which it is assumed to be by design.
DEV_ASSERT(String("headless") == DisplayServer::get_create_function_name(DisplayServer::get_create_function_count() - 1));
for (int i = 0; i < DisplayServer::get_create_function_count(); i++) {
String name = DisplayServer::get_create_function_name(i);
// print_line("\t" + itos(i) + " : " + name);

if (display_driver == name) {
display_driver_idx = i;
break;
}
}

if (display_driver_idx < 0) {
// If the requested driver wasn't found, pick the first entry.
// If all else failed it would be the headless server.
display_driver_idx = 0;
}

Expand All @@ -1484,6 +1485,8 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
audio_driver = GLOBAL_GET("audio/driver/driver");
}

// Make sure that dummy is the last one, which it is assumed to be by design.
DEV_ASSERT(String("Dummy") == AudioDriverManager::get_driver(AudioDriverManager::get_driver_count() - 1)->get_name());
for (int i = 0; i < AudioDriverManager::get_driver_count(); i++) {
if (audio_driver == AudioDriverManager::get_driver(i)->get_name()) {
audio_driver_idx = i;
Expand All @@ -1492,7 +1495,9 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
}

if (audio_driver_idx < 0) {
audio_driver_idx = 0; // 0 Is always available as the dummy driver (no sound)
// If the requested driver wasn't found, pick the first entry.
// If all else failed it would be the dummy driver (no sound).
audio_driver_idx = 0;
}

if (write_movie_path != String()) {
Expand Down Expand Up @@ -1685,10 +1690,12 @@ Error Main::setup2(Thread::ID p_main_tid_override) {
Error err;
display_server = DisplayServer::create(display_driver_idx, rendering_driver, window_mode, window_vsync_mode, window_flags, window_size, err);
if (err != OK || display_server == nullptr) {
//ok i guess we can't use this display server, try other ones
for (int i = 0; i < DisplayServer::get_create_function_count(); i++) {
// We can't use this display server, try other ones as fallback.
// Skip headless (always last registered) because that's not what users
// would expect if they didn't request it explicitly.
for (int i = 0; i < DisplayServer::get_create_function_count() - 1; i++) {
if (i == display_driver_idx) {
continue; //don't try the same twice
continue; // Don't try the same twice.
}
display_server = DisplayServer::create(i, rendering_driver, window_mode, window_vsync_mode, window_flags, window_size, err);
if (err == OK && display_server != nullptr) {
Expand Down

0 comments on commit 833c786

Please sign in to comment.