now creating world array with 16 elements if world array length is 0

pull/12/head
Sara 2023-07-12 02:19:32 +02:00
parent 544f18e9c6
commit c1fa6e2956
1 changed files with 3 additions and 0 deletions

View File

@ -14,6 +14,9 @@ struct {
static inline static inline
int _expand_world() { int _expand_world() {
size_t new_num = _world_objects.num * 2; size_t new_num = _world_objects.num * 2;
if(new_num == 0) {
new_num = 16;
}
object_t** new_list = realloc(_world_objects.objects, new_num * sizeof(object_t*)); object_t** new_list = realloc(_world_objects.objects, new_num * sizeof(object_t*));
if(new_list == NULL) { if(new_list == NULL) {
printf("ERROR: failed to expand world when requesting additional objects\n"); printf("ERROR: failed to expand world when requesting additional objects\n");