@@ -116,7 +116,11 @@ gd::PointKey NavMap::get_point_key(const Vector3 &p_pos) const {
116116}
117117
118118Vector<Vector3> NavMap::get_path (Vector3 p_origin, Vector3 p_destination, bool p_optimize, uint32_t p_navigation_layers, Vector<int32_t > *r_path_types, TypedArray<RID > *r_path_rids, Vector<int64_t > *r_path_owners) const {
119- ERR_FAIL_COND_V_MSG (map_update_id == 0 , Vector<Vector3>(), " NavigationServer map query failed because it was made before first map synchronization." );
119+ RWLockRead read_lock (map_rwlock);
120+ if (map_update_id == 0 ) {
121+ ERR_FAIL_V_MSG (Vector<Vector3>(), " NavigationServer map query failed because it was made before first map synchronization." );
122+ }
123+
120124 // Clear metadata outputs.
121125 if (r_path_types) {
122126 r_path_types->clear ();
@@ -576,7 +580,11 @@ Vector<Vector3> NavMap::get_path(Vector3 p_origin, Vector3 p_destination, bool p
576580}
577581
578582Vector3 NavMap::get_closest_point_to_segment (const Vector3 &p_from, const Vector3 &p_to, const bool p_use_collision) const {
579- ERR_FAIL_COND_V_MSG (map_update_id == 0 , Vector3 (), " NavigationServer map query failed because it was made before first map synchronization." );
583+ RWLockRead read_lock (map_rwlock);
584+ if (map_update_id == 0 ) {
585+ ERR_FAIL_V_MSG (Vector3 (), " NavigationServer map query failed because it was made before first map synchronization." );
586+ }
587+
580588 bool use_collision = p_use_collision;
581589 Vector3 closest_point;
582590 real_t closest_point_d = FLT_MAX ;
@@ -624,24 +632,35 @@ Vector3 NavMap::get_closest_point_to_segment(const Vector3 &p_from, const Vector
624632}
625633
626634Vector3 NavMap::get_closest_point (const Vector3 &p_point) const {
627- ERR_FAIL_COND_V_MSG (map_update_id == 0 , Vector3 (), " NavigationServer map query failed because it was made before first map synchronization." );
635+ RWLockRead read_lock (map_rwlock);
636+ if (map_update_id == 0 ) {
637+ ERR_FAIL_V_MSG (Vector3 (), " NavigationServer map query failed because it was made before first map synchronization." );
638+ }
628639 gd::ClosestPointQueryResult cp = get_closest_point_info (p_point);
629640 return cp.point ;
630641}
631642
632643Vector3 NavMap::get_closest_point_normal (const Vector3 &p_point) const {
633- ERR_FAIL_COND_V_MSG (map_update_id == 0 , Vector3 (), " NavigationServer map query failed because it was made before first map synchronization." );
644+ RWLockRead read_lock (map_rwlock);
645+ if (map_update_id == 0 ) {
646+ ERR_FAIL_V_MSG (Vector3 (), " NavigationServer map query failed because it was made before first map synchronization." );
647+ }
634648 gd::ClosestPointQueryResult cp = get_closest_point_info (p_point);
635649 return cp.normal ;
636650}
637651
638652RID NavMap::get_closest_point_owner (const Vector3 &p_point) const {
639- ERR_FAIL_COND_V_MSG (map_update_id == 0 , RID (), " NavigationServer map query failed because it was made before first map synchronization." );
653+ RWLockRead read_lock (map_rwlock);
654+ if (map_update_id == 0 ) {
655+ ERR_FAIL_V_MSG (RID (), " NavigationServer map query failed because it was made before first map synchronization." );
656+ }
640657 gd::ClosestPointQueryResult cp = get_closest_point_info (p_point);
641658 return cp.owner ;
642659}
643660
644661gd::ClosestPointQueryResult NavMap::get_closest_point_info (const Vector3 &p_point) const {
662+ RWLockRead read_lock (map_rwlock);
663+
645664 gd::ClosestPointQueryResult result;
646665 real_t closest_point_ds = FLT_MAX ;
647666
@@ -770,6 +789,8 @@ void NavMap::remove_agent_as_controlled(NavAgent *agent) {
770789}
771790
772791Vector3 NavMap::get_random_point (uint32_t p_navigation_layers, bool p_uniformly) const {
792+ RWLockRead read_lock (map_rwlock);
793+
773794 const LocalVector<NavRegion *> map_regions = get_regions ();
774795
775796 if (map_regions.is_empty ()) {
@@ -834,6 +855,8 @@ Vector3 NavMap::get_random_point(uint32_t p_navigation_layers, bool p_uniformly)
834855}
835856
836857void NavMap::sync () {
858+ RWLockWrite write_lock (map_rwlock);
859+
837860 // Performance Monitor
838861 int _new_pm_region_count = regions.size ();
839862 int _new_pm_agent_count = agents.size ();
0 commit comments