From ad080c7017c6400489fd46d3e996530d07cff766 Mon Sep 17 00:00:00 2001 From: Relintai Date: Wed, 27 Jul 2022 18:51:18 +0200 Subject: [PATCH] Ported: Disable threaded NavigationMesh bake on unsupported OS. Automatically disables threaded NavigationMesh bake when OS does not support threads. - smix8 https://github.com/godotengine/godot/commit/c3b39ca1e9836a3accfec674a286c2a2fcfe42ed --- doc/classes/NavigationMeshInstance.xml | 2 +- scene/3d/navigation_mesh_instance.cpp | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/doc/classes/NavigationMeshInstance.xml b/doc/classes/NavigationMeshInstance.xml index 6c33ce776..b57c8462c 100644 --- a/doc/classes/NavigationMeshInstance.xml +++ b/doc/classes/NavigationMeshInstance.xml @@ -4,7 +4,7 @@ An instance of a [NavigationMesh]. - An instance of a [NavigationMesh]. It tells the [Navigation] node what can be navigated and what cannot, based on the [NavigationMesh] resource. This should be a child of a [Navigation] node. + Bakes the [NavigationMesh]. If [code]on_thread[/code] is set to [code]true[/code] (default), the baking is done on a separate thread. Baking on separate thread is useful because navigation baking is not a cheap operation. When it is completed, it automatically sets the new [NavigationMesh]. Please note that baking on separate thread may be very slow if geometry is parsed from meshes as async access to each mesh involves heavy synchronization. Also, please note that baking on a separate thread is automatically disabled on operating systems that cannot use threads (such as HTML5 with threads disabled). diff --git a/scene/3d/navigation_mesh_instance.cpp b/scene/3d/navigation_mesh_instance.cpp index d66c88b82..5bd5e101a 100644 --- a/scene/3d/navigation_mesh_instance.cpp +++ b/scene/3d/navigation_mesh_instance.cpp @@ -30,6 +30,7 @@ #include "navigation_mesh_instance.h" +#include "core/os/os.h" #include "mesh_instance.h" #include "navigation.h" #include "scene/resources/mesh.h" @@ -179,7 +180,12 @@ void NavigationMeshInstance::bake_navigation_mesh(bool p_on_thread) { BakeThreadsArgs *args = memnew(BakeThreadsArgs); args->nav_region = this; - if (p_on_thread) { + if (p_on_thread && !OS::get_singleton()->can_use_threads()) { + WARN_PRINT("NavigationMesh bake 'on_thread' will be disabled as the current OS does not support multiple threads." + "\nAs a fallback the navigation mesh will bake on the main thread which can cause framerate issues."); + } + + if (p_on_thread && OS::get_singleton()->can_use_threads()) { bake_thread.start(_bake_navigation_mesh, args); } else { _bake_navigation_mesh(args);