From 0a083f5a9a747083bbc3a1f0689e76ac5fc3a3b9 Mon Sep 17 00:00:00 2001 From: quou Date: Fri, 5 May 2023 09:25:20 +1000 Subject: Add a check to make sure max_entities doesn't get overflowed. --- world.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'world.c') diff --git a/world.c b/world.c index 3b736e6..920484c 100644 --- a/world.c +++ b/world.c @@ -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] : -- cgit v1.2.3-54-g00ecf