From a2043f124d0a2f913a01911f83b18bacf11738ef Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Sun, 18 Aug 2024 23:55:15 +0200 Subject: [PATCH] Improve error messages for invalid rendering drivers/methods on the command line - Deduplicate rendering driver names. - Tweak grammar and punctuation to be consistent across both messages. - Use "rendering method" terminology in the relevant error message. Preview: `--rendering-driver unknown`: Unknown rendering driver 'unknown', aborting. Valid options are 'vulkan', 'opengl3', 'opengl3_es' and 'dummy'. `--rendering-method unknown`: Unknown rendering method 'unknown', aborting. Valid options are 'forward_plus', 'mobile' and 'gl_compatibility'. --- main/main.cpp | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/main/main.cpp b/main/main.cpp index bdae1bb1b07..e5105d92a59 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -2175,7 +2175,20 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph if (rendering_method != "forward_plus" && rendering_method != "mobile" && rendering_method != "gl_compatibility") { - OS::get_singleton()->print("Unknown renderer name '%s', aborting. Valid options are: %s\n", rendering_method.utf8().get_data(), renderer_hints.utf8().get_data()); + OS::get_singleton()->print("Unknown rendering method '%s', aborting.\nValid options are ", + rendering_method.utf8().get_data()); + + const Vector rendering_method_hints = renderer_hints.split(","); + for (int i = 0; i < rendering_method_hints.size(); i++) { + if (i == rendering_method_hints.size() - 1) { + OS::get_singleton()->print(" and "); + } else if (i != 0) { + OS::get_singleton()->print(", "); + } + OS::get_singleton()->print("'%s'", rendering_method_hints[i].utf8().get_data()); + } + + OS::get_singleton()->print(".\n"); goto error; } } @@ -2201,14 +2214,27 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph OS::get_singleton()->print("Unknown rendering driver '%s', aborting.\nValid options are ", rendering_driver.utf8().get_data()); + // Deduplicate driver entries, as a rendering driver may be supported by several display servers. + Vector unique_rendering_drivers; for (int i = 0; i < DisplayServer::get_create_function_count(); i++) { Vector r_drivers = DisplayServer::get_create_function_rendering_drivers(i); for (int d = 0; d < r_drivers.size(); d++) { - OS::get_singleton()->print("'%s', ", r_drivers[d].utf8().get_data()); + if (!unique_rendering_drivers.has(r_drivers[d])) { + unique_rendering_drivers.append(r_drivers[d]); + } } } + for (int i = 0; i < unique_rendering_drivers.size(); i++) { + if (i == unique_rendering_drivers.size() - 1) { + OS::get_singleton()->print(" and "); + } else if (i != 0) { + OS::get_singleton()->print(", "); + } + OS::get_singleton()->print("'%s'", unique_rendering_drivers[i].utf8().get_data()); + } + OS::get_singleton()->print(".\n"); goto error;