diff options
author | quou <quou@disroot.org> | 2023-05-05 09:25:20 +1000 |
---|---|---|
committer | quou <quou@disroot.org> | 2023-05-05 09:25:20 +1000 |
commit | 0a083f5a9a747083bbc3a1f0689e76ac5fc3a3b9 (patch) | |
tree | ef9a9d883fab808b1d13b8a56b94afb12597bf0f | |
parent | 7fa5b3c842c276859c7d4016b9660e1b16ac30c5 (diff) |
Add a check to make sure max_entities doesn't get overflowed.
-rw-r--r-- | world.c | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -1,4 +1,6 @@ #include "world.h" +#include "platform.h" +#include "error.h" void init_world(World* world) { world->entity_count = 0; @@ -7,6 +9,16 @@ void init_world(World* world) { Entity new_entity(World* world) { Entity e; +#if DEBUG + if ( + world->entity_count >= max_entities + && world->recycle_bin_count == 0 + ) { + platform_err("Too many entities.\n"); + platform_abort(error_out_of_memory); + } +#endif + e = world->recycle_bin_count > 0 ? world->recycle_bin[--world->recycle_bin_count] : |