From bb5f16033dd377b465c5eaadbe35b6c1b4b3a082 Mon Sep 17 00:00:00 2001 From: smix8 <52464204+smix8@users.noreply.github.com> Date: Fri, 14 Jul 2023 16:15:14 +0200 Subject: [PATCH] Make NavigationRegion3D baking NavMesh on the main thread not finish deferred Makes NavigationRegion3D baking NavMesh on the main thread not finish deferred. --- scene/3d/navigation_region_3d.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scene/3d/navigation_region_3d.cpp b/scene/3d/navigation_region_3d.cpp index 194d3082dfd..c9c44307870 100644 --- a/scene/3d/navigation_region_3d.cpp +++ b/scene/3d/navigation_region_3d.cpp @@ -262,11 +262,19 @@ void _bake_navigation_mesh(void *p_user_data) { Ref source_geometry_data = args->source_geometry_data; NavigationServer3D::get_singleton()->bake_from_source_geometry_data(nav_mesh, source_geometry_data); - args->nav_region->call_deferred(SNAME("_bake_finished"), nav_mesh); + if (!Thread::is_main_thread()) { + args->nav_region->call_deferred(SNAME("_bake_finished"), nav_mesh); + } else { + args->nav_region->_bake_finished(nav_mesh); + } memdelete(args); } else { ERR_PRINT("Can't bake the navigation mesh if the `NavigationMesh` resource doesn't exist"); - args->nav_region->call_deferred(SNAME("_bake_finished"), Ref()); + if (!Thread::is_main_thread()) { + args->nav_region->call_deferred(SNAME("_bake_finished"), Ref()); + } else { + args->nav_region->_bake_finished(Ref()); + } memdelete(args); } }