Fix memory leak when iterating path

This commit is contained in:
2023-11-23 19:35:59 +01:00
parent a17450dd81
commit 6e977b7433
6 changed files with 17 additions and 2 deletions

View File

@@ -78,6 +78,7 @@ void entityUpdateKinematic(ecs_iter_t *it) {
}
void entityFollowPath(ecs_iter_t *it) {
const Game *game = ecs_singleton_get(ECS, Game);
Position *position = ecs_field(it, Position, 1);
Rotation *rotation = ecs_field(it, Rotation, 2);
Velocity *velocity = ecs_field(it, Velocity, 3);
@@ -95,6 +96,8 @@ void entityFollowPath(ecs_iter_t *it) {
path[i].curWaypoint++;
if (path[i].curWaypoint >= path[i].paths->numWaypoints) {
path[i].curWaypoint = 0;
PathData *oldPath = path[i].paths;
bzObjectPoolRelease(game->pools.pathData, oldPath);
path[i].paths = path[i].paths->next;
if (!path[i].paths) ecs_remove(ECS, it->entities[i], Path);
}