Skip to content

Commit

Permalink
Avoid adding entities >= num_edicts to the free list (#242, #266)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-drexler committed Jul 21, 2024
1 parent 9efccb6 commit 729a2d1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Quake/host_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2656,8 +2656,10 @@ static void Host_Loadgame_f (void)
}

// Free edicts allocated during map loading but no longer used after restoring saved game state
// Note: we use ED_ClearEdict instead of ED_Free to avoid placing entities >= num_edicts in the free list
// This is different from QuakeSpasm, which doesn't use a free list
for (i = entnum; i < qcvm->num_edicts; i++)
ED_Free (EDICT_NUM (i));
ED_ClearEdict (EDICT_NUM (i));

qcvm->num_edicts = entnum;
qcvm->time = time;
Expand Down
5 changes: 4 additions & 1 deletion Quake/pr_edict.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,11 @@ Sets everything to NULL
*/
void ED_ClearEdict (edict_t *e)
{
if (!e->free)
SV_UnlinkEdict (e);
else
ED_RemoveFromFreeList (e);
memset (&e->v, 0, qcvm->progs->entityfields * 4);
ED_RemoveFromFreeList (e);
}

/*
Expand Down

0 comments on commit 729a2d1

Please sign in to comment.