diff options
author | smix8 <52464204+smix8@users.noreply.github.com> | 2023-02-14 01:28:14 +0100 |
---|---|---|
committer | smix8 <52464204+smix8@users.noreply.github.com> | 2023-02-14 01:39:21 +0100 |
commit | fef6ffabe5f466545cf26e1a5e401d1c14825f2c (patch) | |
tree | 44029f318a467d4e51ce8502e75456c30c0778d8 /scene/2d | |
parent | 853c36ca0b6a4b8982215115b1fb1b62b58f2d98 (diff) |
Fix TileMap NavigationServer 'Invalid ID' error
Fixes NavigationServer 'Invalid ID' error of the TileMap.
The issue was not caused directly by the TileMap but with the late call to get_world_2d()->get_navigation_map() while everything is shut down abruptly e.g. game window closed or Editor "Reload Saved Scene" function.
Diffstat (limited to 'scene/2d')
-rw-r--r-- | scene/2d/tile_map.cpp | 7 | ||||
-rw-r--r-- | scene/2d/tile_map.h | 1 |
2 files changed, 6 insertions, 2 deletions
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index 2e0b16388f..11e59d9858 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -754,8 +754,9 @@ TileMap::VisibilityMode TileMap::get_navigation_visibility_mode() { void TileMap::set_navigation_map(int p_layer, RID p_map) { ERR_FAIL_INDEX(p_layer, (int)layers.size()); - + ERR_FAIL_COND_MSG(!is_inside_tree(), "A TileMap navigation map can only be changed while inside the SceneTree."); layers[p_layer].navigation_map = p_map; + layers[p_layer].uses_world_navigation_map = p_map == get_world_2d()->get_navigation_map(); } RID TileMap::get_navigation_map(int p_layer) const { @@ -1111,10 +1112,12 @@ void TileMap::_navigation_update_layer(int p_layer) { if (p_layer == 0 && is_inside_tree()) { // Use the default World2D navigation map for the first layer when empty. layers[p_layer].navigation_map = get_world_2d()->get_navigation_map(); + layers[p_layer].uses_world_navigation_map = true; } else { RID new_layer_map = NavigationServer2D::get_singleton()->map_create(); NavigationServer2D::get_singleton()->map_set_active(new_layer_map, true); layers[p_layer].navigation_map = new_layer_map; + layers[p_layer].uses_world_navigation_map = false; } } } @@ -1124,7 +1127,7 @@ void TileMap::_navigation_cleanup_layer(int p_layer) { ERR_FAIL_NULL(NavigationServer2D::get_singleton()); if (layers[p_layer].navigation_map.is_valid()) { - if (is_inside_tree() && layers[p_layer].navigation_map == get_world_2d()->get_navigation_map()) { + if (layers[p_layer].uses_world_navigation_map) { // Do not delete the World2D default navigation map. return; } diff --git a/scene/2d/tile_map.h b/scene/2d/tile_map.h index 62d7612be2..e9c1cb0c11 100644 --- a/scene/2d/tile_map.h +++ b/scene/2d/tile_map.h @@ -212,6 +212,7 @@ private: HashMap<Vector2i, TileMapQuadrant> quadrant_map; SelfList<TileMapQuadrant>::List dirty_quadrant_list; RID navigation_map; + bool uses_world_navigation_map = false; }; LocalVector<TileMapLayer> layers; int selected_layer = -1; |