Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly clear scene tiles #79941

Merged
merged 1 commit into from
Jul 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions scene/2d/tile_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,18 +773,7 @@ void TileMapLayer::_scenes_update_dirty_quadrants(SelfList<TileMapQuadrant>::Lis
SelfList<TileMapQuadrant> *q_list_element = r_dirty_quadrant_list.first();
while (q_list_element) {
TileMapQuadrant &q = *q_list_element->self();

// Clear the scenes if instance cache was cleared.
if (instantiated_scenes.is_empty()) {
for (const KeyValue<Vector2i, String> &E : q.scenes) {
Node *node = tile_map_node->get_node_or_null(E.value);
if (node) {
node->queue_free();
}
}
}

q.scenes.clear();
Copy link
Member Author

@KoBeWi KoBeWi Jul 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

q.scenes should not be cleared if the cache exists, otherwise the scenes can't be removed anymore.

_scenes_cleanup_quadrant(&q);

// Recreate the scenes.
for (const Vector2i &E_cell : q.cells) {
Expand Down Expand Up @@ -1562,6 +1551,7 @@ void TileMapLayer::clear_instantiated_scenes() {

void TileMapLayer::clear_internals() {
// Clear quadrants.
clear_instantiated_scenes();
while (quadrant_map.size()) {
_erase_quadrant(quadrant_map.begin());
}
Expand Down Expand Up @@ -1962,6 +1952,7 @@ TileData *TileMapLayer::get_cell_tile_data(const Vector2i &p_coords, bool p_use_

void TileMapLayer::clear() {
// Remove all tiles.
clear_instantiated_scenes();
clear_internals();
tile_map.clear();
recreate_internals();
Expand Down