riksweeney / edgar

A 2D platform game with a persistent world. When Edgar's father fails to return home after venturing out one dark and stormy night, Edgar fears the worst: he has been captured by the evil sorcerer who lives in a fortress beyond the forbidden swamp.
https://www.parallelrealities.co.uk/games/edgar
116 stars 28 forks source link

Fix crash when entity is freed while still being referenced by player #49

Closed lumidify closed 3 years ago

lumidify commented 3 years ago

The game would crash at certain points when an entity was referenced by the player that had already been freed in entity.c. Specifically, it crashed on line 905 of src/player.c while trying to dereference self->standingOn->dirX. After some digging, I found that the entity which was currently set as self->standingOn had already been freed in drawEntities (in src/entity.c) because isReferenced was not checking if the entity was being referenced by the player. This patch should fix that. Note that I don't know if this would be the correct way to check that, but it fixed the crash for me.