From 22285c8fd964230fa90e3e8b30a3b49a6ec226e0 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Tue, 5 Aug 2025 23:43:33 +0200 Subject: [PATCH] Document `OS.get_video_adapter_driver_info()` being slow to call the first time - Add a code sample that shows how to call it from a thread to avoid blocking the engine. --- doc/classes/OS.xml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/doc/classes/OS.xml b/doc/classes/OS.xml index 774ee21ed56..a6f14f867b9 100644 --- a/doc/classes/OS.xml +++ b/doc/classes/OS.xml @@ -611,6 +611,25 @@ The first element holds the driver name, such as [code]nvidia[/code], [code]amdgpu[/code], etc. The second element holds the driver version. For example, on 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 Linux/BSD and Windows when not running in headless mode. On other platforms, it returns an empty array. + [b]Note:[/b] This method will run slowly the first time it is called in a session; it can take several seconds depending on the operating system and hardware. It is blocking if called on the main thread, so it's recommended to call it on a separate thread using [Thread]. This allows the engine to keep running while the information is being retrieved. However, [method get_video_adapter_driver_info] is [i]not[/i] thread-safe, so it should not be called from multiple threads at the same time. + [codeblocks] + [gdscript] + var thread = Thread.new() + + func _ready(): + thread.start( + func(): + var driver_info = OS.get_video_adapter_driver_info() + if not driver_info.is_empty(): + print("Driver: %s %s" % [driver_info[0], driver_info[1]]) + else: + print("Driver: (unknown)") + ) + + func _exit_tree(): + thread.wait_to_finish() + [/gdscript] + [/codeblocks]