Fix memory leak when iterating path
This commit is contained in:
@@ -191,7 +191,7 @@ void update(float dt, void *userData) {
|
||||
snprintf(titleBuf, sizeof(titleBuf), "FPS: %d | %.2f ms", GetFPS(), GetFrameTime() * 1000);
|
||||
SetWindowTitle(titleBuf);
|
||||
|
||||
updatePlayerInput(NULL);
|
||||
updatePlayerInput(NULL);
|
||||
}
|
||||
|
||||
void render(float dt, void *userData) {
|
||||
@@ -224,6 +224,7 @@ void imguiRender(float dt, void *userData) {
|
||||
|
||||
igSetNextWindowSize((ImVec2){300, 400}, ImGuiCond_FirstUseEver);
|
||||
igBegin("Debug Menu", NULL, 0);
|
||||
igText("Num paths from pool available: %llu", bzObjectPoolCalcNumFree(game->pools.pathData));
|
||||
const char *inputState = "NONE";
|
||||
switch (input->state) {
|
||||
case INPUT_NONE:
|
||||
|
||||
@@ -84,7 +84,6 @@ static void smoothPath(BzTileMap *map, PathData *pathData, BzObjectPool *pool) {
|
||||
|
||||
prevIdx++;
|
||||
nextIdx++;
|
||||
bzLogInfo("%llu,%llu", prevIdx, nextIdx);
|
||||
|
||||
if (prevIdx >= currPathLen) {
|
||||
prevPath = prevPath->next;
|
||||
|
||||
@@ -43,6 +43,7 @@ void entityUpdateSpatialID(ecs_iter_t *it);
|
||||
void entityUpdateKinematic(ecs_iter_t *it);
|
||||
|
||||
/*
|
||||
* 0: Game (singleton) for object pool
|
||||
* 1: Position
|
||||
* 2: Rotation
|
||||
* 3: Velocity
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user