Do not erare the dictionary we are iterating on

This commit is contained in:
aidandavey 2025-11-05 21:46:25 +00:00
parent 3a50b8e3f1
commit c6b22fd596
1 changed files with 5 additions and 3 deletions

View File

@ -390,6 +390,11 @@ void Terrain3DInstancer::_destroy_mmi_by_location(const Vector2i &p_region_loc,
for (const auto &cell : cells) {
_destroy_mmi_by_cell(p_region_loc, p_mesh_id, cell);
}
// After all cells are destroyed, if the region is now empty, erase it
if (_mmi_rids.count(p_region_loc) > 0 && _mmi_rids[p_region_loc].empty()) {
_mmi_rids.erase(p_region_loc);
}
}
void Terrain3DInstancer::_destroy_mmi_by_cell(const Vector2i &p_region_loc, const int p_mesh_id, const Vector2i p_cell, const int p_lod) {
@ -429,9 +434,6 @@ void Terrain3DInstancer::_destroy_mmi_by_cell(const Vector2i &p_region_loc, cons
LOG(EXTREME, "Removing mesh ", mesh_key, " from cell MMI dictionary");
mesh_mmi_dict.erase(mesh_key); // invalidates cell_mmi_dict
}
// This invalidates mesh_mmi_dict here and for calling functions
_mmi_rids.erase(p_region_loc);
}
}