From 2c5e2196bd585c45e0f83236b6a23b6afbfa31a6 Mon Sep 17 00:00:00 2001 From: MJacred Date: Tue, 6 Jun 2023 23:29:36 +0200 Subject: [PATCH] Replace get_rendering_device() call to prevent crashes on OpenGL. And make OpenGL video adapter info align with Vulkan. --- drivers/gles3/rasterizer_gles3.cpp | 3 +-- drivers/gles3/storage/utilities.cpp | 8 ++++++-- editor/editor_node.cpp | 2 +- platform/linuxbsd/os_linuxbsd.cpp | 6 +++--- platform/windows/os_windows.cpp | 4 ++-- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/drivers/gles3/rasterizer_gles3.cpp b/drivers/gles3/rasterizer_gles3.cpp index 6748e933836..d66e5f51ede 100644 --- a/drivers/gles3/rasterizer_gles3.cpp +++ b/drivers/gles3/rasterizer_gles3.cpp @@ -180,8 +180,7 @@ typedef void (*DEBUGPROCARB)(GLenum source, typedef void (*DebugMessageCallbackARB)(DEBUGPROCARB callback, const void *userParam); void RasterizerGLES3::initialize() { - // NVIDIA suffixes all GPU model names with "/PCIe/SSE2" in OpenGL (but not Vulkan). This isn't necessary to display nowadays, so it can be trimmed. - print_line(vformat("OpenGL API %s - Compatibility - Using Device: %s - %s", RS::get_singleton()->get_video_adapter_api_version(), RS::get_singleton()->get_video_adapter_vendor(), RS::get_singleton()->get_video_adapter_name().trim_suffix("/PCIe/SSE2"))); + print_line(vformat("OpenGL API %s - Compatibility - Using Device: %s - %s", RS::get_singleton()->get_video_adapter_api_version(), RS::get_singleton()->get_video_adapter_vendor(), RS::get_singleton()->get_video_adapter_name())); } void RasterizerGLES3::finalize() { diff --git a/drivers/gles3/storage/utilities.cpp b/drivers/gles3/storage/utilities.cpp index 30c3e61ee7e..5f21d8f70a1 100644 --- a/drivers/gles3/storage/utilities.cpp +++ b/drivers/gles3/storage/utilities.cpp @@ -328,11 +328,15 @@ uint64_t Utilities::get_rendering_info(RS::RenderingInfo p_info) { } String Utilities::get_video_adapter_name() const { - return (const char *)glGetString(GL_RENDERER); + const String rendering_device_name = (const char *)glGetString(GL_RENDERER); + // NVIDIA suffixes all GPU model names with "/PCIe/SSE2" in OpenGL (but not Vulkan). This isn't necessary to display nowadays, so it can be trimmed. + return rendering_device_name.trim_suffix("/PCIe/SSE2"); } String Utilities::get_video_adapter_vendor() const { - return (const char *)glGetString(GL_VENDOR); + const String rendering_device_vendor = (const char *)glGetString(GL_VENDOR); + // NVIDIA suffixes its vendor name with " Corporation". This is neither necessary to process nor display. + return rendering_device_vendor.trim_suffix(" Corporation"); } RenderingDevice::DeviceType Utilities::get_video_adapter_type() const { diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index e0863a5e569..bc61661a83f 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -4382,7 +4382,7 @@ String EditorNode::_get_system_info() const { String driver_name = GLOBAL_GET("rendering/rendering_device/driver"); String rendering_method = GLOBAL_GET("rendering/renderer/rendering_method"); - const String rendering_device_name = RenderingServer::get_singleton()->get_rendering_device()->get_device_name(); + const String rendering_device_name = RenderingServer::get_singleton()->get_video_adapter_name(); RenderingDevice::DeviceType device_type = RenderingServer::get_singleton()->get_video_adapter_type(); String device_type_string; diff --git a/platform/linuxbsd/os_linuxbsd.cpp b/platform/linuxbsd/os_linuxbsd.cpp index 2c093b00e76..b843becfe00 100644 --- a/platform/linuxbsd/os_linuxbsd.cpp +++ b/platform/linuxbsd/os_linuxbsd.cpp @@ -252,7 +252,7 @@ String OS_LinuxBSD::get_version() const { } Vector OS_LinuxBSD::get_video_adapter_driver_info() const { - if (RenderingServer::get_singleton()->get_rendering_device() == nullptr) { + if (RenderingServer::get_singleton() == nullptr) { return Vector(); } @@ -261,8 +261,8 @@ Vector OS_LinuxBSD::get_video_adapter_driver_info() const { return info; } - const String rendering_device_name = RenderingServer::get_singleton()->get_rendering_device()->get_device_name(); // e.g. `NVIDIA GeForce GTX 970` - const String rendering_device_vendor = RenderingServer::get_singleton()->get_rendering_device()->get_device_vendor_name(); // e.g. `NVIDIA` + const String rendering_device_name = RenderingServer::get_singleton()->get_video_adapter_name(); // e.g. `NVIDIA GeForce GTX 970` + const String rendering_device_vendor = RenderingServer::get_singleton()->get_video_adapter_vendor(); // e.g. `NVIDIA` const String card_name = rendering_device_name.trim_prefix(rendering_device_vendor).strip_edges(); // -> `GeForce GTX 970` String vendor_device_id_mappings; diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index 2653efed71f..411811969e4 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -449,7 +449,7 @@ String OS_Windows::get_version() const { } Vector OS_Windows::get_video_adapter_driver_info() const { - if (RenderingServer::get_singleton()->get_rendering_device() == nullptr) { + if (RenderingServer::get_singleton() == nullptr) { return Vector(); } @@ -467,7 +467,7 @@ Vector OS_Windows::get_video_adapter_driver_info() const { String driver_name; String driver_version; - const String device_name = RenderingServer::get_singleton()->get_rendering_device()->get_device_name(); + const String device_name = RenderingServer::get_singleton()->get_video_adapter_name(); if (device_name.is_empty()) { return Vector(); }