diff --git a/src/util/AreaMap2D.hpp b/src/util/AreaMap2D.hpp index 9ec0e439d..8ad3ff1d7 100644 --- a/src/util/AreaMap2D.hpp +++ b/src/util/AreaMap2D.hpp @@ -120,9 +120,14 @@ namespace util { if (lx < 0 || ly < 0 || lx >= sizeX || ly >= sizeY) { return; } + auto& element = firstBuffer[ly * sizeX + lx]; + if (element == T{}) { + return; + } if (outCallback) - outCallback(x, y, firstBuffer[ly * sizeX + lx]); - firstBuffer[ly * sizeX + lx] = T{}; + outCallback(x, y, element); + element = T{}; + valuesCount--; } void setOutCallback(const OutCallback& callback) {