diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2022-07-02 10:54:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-02 10:54:46 +0200 |
commit | 2b31c88982e4fdcbc8f0d7ba5d02cfd451a1df88 (patch) | |
tree | 94ea5869190f13c6f381bba8e3fcf68e90083d07 /main | |
parent | ec1348a72a510f68dfd2698bc368b29e2c72cbae (diff) | |
parent | 833c7868136a6b9c8557bc51f1e97f22dd6dd738 (diff) |
Merge pull request #62556 from akien-mga/displayserver-no-headless-fallback
DisplayServer: Don't fallback to headless
Diffstat (limited to 'main')
-rw-r--r-- | main/main.cpp | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/main/main.cpp b/main/main.cpp index 0205b9c157..f7c192001b 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1460,11 +1460,10 @@ 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; @@ -1472,6 +1471,8 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph } 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; } @@ -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; @@ -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()) { @@ -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) { |