From 2562d675f7a143f2c232b5f0da17c72ae4239705 Mon Sep 17 00:00:00 2001 From: snit Date: Sat, 28 Sep 2024 20:40:55 -0500 Subject: [PATCH] null entities placed out of bounds --- src/main.c | 6 +++--- src/world.c | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main.c b/src/main.c index 823a35a..f297261 100644 --- a/src/main.c +++ b/src/main.c @@ -12,17 +12,17 @@ int main(void) { if (err != ERR_OK) goto error; err = world_register_entity(&world, "john", 'j'); - if (err != ERR_OK) goto error_register; + if (err != ERR_OK) goto error_free; err = world_place_entity(&world, 1, 1, 2); - if (err != ERR_OK) goto error_register; + if (err != ERR_OK) goto error_free; world_print(&world); world_free(&world); return 0; -error_register: +error_free: world_free(&world); error: printf("ERROR: %s", ERROR_STRS[err]); diff --git a/src/world.c b/src/world.c index 0c08c9d..e9cf612 100644 --- a/src/world.c +++ b/src/world.c @@ -11,7 +11,11 @@ enum error_t world_init(struct world_t *self, size_t height, size_t width) { self->height = height; self->width = width; - memset(self->entities, 0, MAX_ENTITIES * sizeof(struct entity_t)); + for (size_t i = 0; i < MAX_ENTITIES; i++) { + self->entities[i].id = 0; + self->entities[i].x = self->width; + self->entities[i].y = self->height; + } enum error_t err = entity_registry_init(&self->registered_entities); if (err != ERR_OK) return err;