fix: access to deleted Sensor

This commit is contained in:
MihailRis 2024-08-01 17:10:30 +03:00
parent f8907f7db1
commit 50a388c539
3 changed files with 12 additions and 0 deletions

View File

@ -347,6 +347,12 @@ void Entities::clean() {
if (!registry.get<EntityId>(it->second).destroyFlag) { if (!registry.get<EntityId>(it->second).destroyFlag) {
++it; ++it;
} else { } else {
auto& rigidbody = registry.get<Rigidbody>(it->second);
// todo: refactor
auto physics = level->physics.get();
for (auto& sensor : rigidbody.sensors) {
physics->removeSensor(&sensor);
}
uids.erase(it->second); uids.erase(it->second);
registry.destroy(it->second); registry.destroy(it->second);
it = entities.erase(it); it = entities.erase(it);

View File

@ -273,3 +273,7 @@ bool PhysicsSolver::isBlockInside(int x, int y, int z, Block* def, blockstate st
} }
return false; return false;
} }
void PhysicsSolver::removeSensor(Sensor* sensor) {
sensors.erase(std::remove(sensors.begin(), sensors.end(), sensor), sensors.end());
}

View File

@ -39,6 +39,8 @@ public:
void setSensors(std::vector<Sensor*> sensors) { void setSensors(std::vector<Sensor*> sensors) {
this->sensors = std::move(sensors); this->sensors = std::move(sensors);
} }
void removeSensor(Sensor* sensor);
}; };
#endif // PHYSICS_PHYSICSSOLVER_HPP_ #endif // PHYSICS_PHYSICSSOLVER_HPP_