summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzCubed3 <liamr2023@gmail.com>2022-10-27 13:52:38 -0700
committerzCubed3 <liamr2023@gmail.com>2022-10-27 15:45:21 -0700
commite7091d07cdd15f9ef3c0083a02532efa2866298c (patch)
tree0d7b252757913dd8074e6076a4e74cd48bd42fac
parent4dc2c8ae6fe954f8c5c6627803f0a087ee1a2488 (diff)
Fix OS.get_video_adapter_driver_info crash
-rw-r--r--doc/classes/OS.xml2
-rw-r--r--platform/linuxbsd/os_linuxbsd.cpp4
-rw-r--r--platform/windows/os_windows.cpp4
3 files changed, 9 insertions, 1 deletions
diff --git a/doc/classes/OS.xml b/doc/classes/OS.xml
index 3aa26cbb21..c8491b3a03 100644
--- a/doc/classes/OS.xml
+++ b/doc/classes/OS.xml
@@ -451,7 +451,7 @@
Returns the video adapter driver name and version for the user's currently active graphics card.
The first element holds the driver name, such as [code]nvidia[/code], [code]amdgpu[/code], etc.
The second element holds the driver version. For e.g. the [code]nvidia[/code] driver on a Linux/BSD platform, the version is in the format [code]510.85.02[/code]. For Windows, the driver's format is [code]31.0.15.1659[/code].
- [b]Note:[/b] This method is only supported on the platforms Linux/BSD and Windows. It returns an empty array on other platforms.
+ [b]Note:[/b] This method is only supported on the platforms Linux/BSD and Windows when not running in headless mode. It returns an empty array on other platforms.
</description>
</method>
<method name="has_environment" qualifiers="const">
diff --git a/platform/linuxbsd/os_linuxbsd.cpp b/platform/linuxbsd/os_linuxbsd.cpp
index 995a904398..11b667fcef 100644
--- a/platform/linuxbsd/os_linuxbsd.cpp
+++ b/platform/linuxbsd/os_linuxbsd.cpp
@@ -246,6 +246,10 @@ String OS_LinuxBSD::get_version() const {
}
Vector<String> OS_LinuxBSD::get_video_adapter_driver_info() const {
+ if (RenderingServer::get_singleton()->get_rendering_device() == nullptr) {
+ return Vector<String>();
+ }
+
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 card_name = rendering_device_name.trim_prefix(rendering_device_vendor).strip_edges(); // -> `GeForce GTX 970`
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp
index 5ca064e523..a8911788fe 100644
--- a/platform/windows/os_windows.cpp
+++ b/platform/windows/os_windows.cpp
@@ -311,6 +311,10 @@ String OS_Windows::get_version() const {
}
Vector<String> OS_Windows::get_video_adapter_driver_info() const {
+ if (RenderingServer::get_singleton()->get_rendering_device() == nullptr) {
+ return Vector<String>();
+ }
+
REFCLSID clsid = CLSID_WbemLocator; // Unmarshaler CLSID
REFIID uuid = IID_IWbemLocator; // Interface UUID
IWbemLocator *wbemLocator = NULL; // to get the services