fix: UB with LivingEntities::pushEntities

This commit is contained in:
Tropical 2026-04-11 09:56:20 -07:00
parent 76788f1708
commit f7e555ea6b
2 changed files with 10 additions and 6 deletions

View file

@ -485,7 +485,7 @@ File Minecraft::getWorkingDirectory(const std::string& applicationName) {
return workingDirectory;
} else {
Log::info("Could not locate user's home directory. This platform is likely missing an implementation of Minecraft::getWorkingDirectory.");
Log::info("Could not locate user's home directory. This platform is likely missing an implementation of Minecraft::getWorkingDirectory.\n");
assert(0);
}
}

View file

@ -1604,11 +1604,15 @@ void LivingEntity::pushEntities() {
AABB grown = bb.grow(0.2, 0, 0.2);
std::vector<std::shared_ptr<Entity>>* entities =
level->getEntities(shared_from_this(), &grown);
if (entities != nullptr && !entities->empty()) {
auto itEnd = entities->end();
for (auto it = entities->begin(); it != itEnd; it++) {
std::shared_ptr<Entity> e = *it; // entities->at(i);
if (e and !e->removed and e->isPushable()) push(e);
if (entities == nullptr || entities->empty()) {
return;
}
std::vector<std::shared_ptr<Entity>> prev_entities = *entities;
for (const std::shared_ptr<Entity>& e : prev_entities) {
if (e && !e->removed && e->isPushable()) {
push(e);
}
}
}