Fix OS.get_video_adapter_driver_info crash

This commit is contained in:
zCubed3 2022-10-27 13:52:38 -07:00
parent 4dc2c8ae6f
commit e7091d07cd
No known key found for this signature in database
GPG key ID: 32B69C3A67288994
3 changed files with 9 additions and 1 deletions

View file

@ -451,7 +451,7 @@
Returns the video adapter driver name and version for the user's currently active graphics card. 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 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]. 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> </description>
</method> </method>
<method name="has_environment" qualifiers="const"> <method name="has_environment" qualifiers="const">

View file

@ -246,6 +246,10 @@ String OS_LinuxBSD::get_version() const {
} }
Vector<String> OS_LinuxBSD::get_video_adapter_driver_info() 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_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_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` const String card_name = rendering_device_name.trim_prefix(rendering_device_vendor).strip_edges(); // -> `GeForce GTX 970`

View file

@ -311,6 +311,10 @@ String OS_Windows::get_version() const {
} }
Vector<String> OS_Windows::get_video_adapter_driver_info() 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 REFCLSID clsid = CLSID_WbemLocator; // Unmarshaler CLSID
REFIID uuid = IID_IWbemLocator; // Interface UUID REFIID uuid = IID_IWbemLocator; // Interface UUID
IWbemLocator *wbemLocator = NULL; // to get the services IWbemLocator *wbemLocator = NULL; // to get the services