Crushed the last memory leakage bug in the chunk update

This commit is contained in:
Eric-Paul Ickhorn 2023-10-17 14:39:20 +02:00
parent fb0aa65d00
commit 3a017e678e
5 changed files with 18 additions and 6 deletions

View File

@ -38,6 +38,10 @@ void tc_draw_chunkloader_zone(tc_chunkloader_s *loader)
tc_chunklist_s *list = &loader->chunklist; tc_chunklist_s *list = &loader->chunklist;
for(tc_chunklist_entry_s *current = list->first; current != NULL; current = current->next) for(tc_chunklist_entry_s *current = list->first; current != NULL; current = current->next)
{ {
if(current->entity == NULL)
{
return;
}
tc_send_pointer_to_entity(current->entity, "draw", 0); tc_send_pointer_to_entity(current->entity, "draw", 0);
} }

View File

@ -117,6 +117,9 @@ void tc_chunklist_remove_item(tc_chunklist_s *list, tc_entity_s *chunk)
if(entry->previous != NULL) if(entry->previous != NULL)
entry->previous->next = entry->next; entry->previous->next = entry->next;
if(entry->next != NULL)
entry->next->previous = entry->previous;
entry->entity = NULL; entry->entity = NULL;
list->first_free = entry; list->first_free = entry;
} }
@ -130,7 +133,7 @@ tc_chunkloader_s tc_create_chunkloader(tc_chunk_location_s location)
loader.extent.y = UPDATE_DISTANCE * 2 + 1; loader.extent.y = UPDATE_DISTANCE * 2 + 1;
loader.extent.z = UPDATE_DISTANCE * 2 + 1; loader.extent.z = UPDATE_DISTANCE * 2 + 1;
loader.center = location; loader.center = location;
loader.chunklist = tc_create_chunklist(200); loader.chunklist = tc_create_chunklist(512);
loader.needs_reload = FALSE; loader.needs_reload = FALSE;
return loader; return loader;

View File

@ -325,7 +325,8 @@ void tc_send_pointer_to_entity(tc_entity_s *entity, char *event_name, void *poin
tc_entity_event_s event; tc_entity_event_s event;
event.identifier = event_name; event.identifier = event_name;
event.value.pointer = pointer; event.value.pointer = pointer;
entity->type->functions.fn_send_event(entity, event); tc_entity_type_s *type = entity->type;
type->functions.fn_send_event(entity, event);
} }
void tc_send_string_to_entity(tc_entity_s *entity, char *event_name, char *string) void tc_send_string_to_entity(tc_entity_s *entity, char *event_name, char *string)

View File

@ -39,8 +39,10 @@ void tc_delete_chunk_entity(tc_entity_s *entity)
if(chunk->vertex_uvs != NULL) free(chunk->vertex_uvs); if(chunk->vertex_uvs != NULL) free(chunk->vertex_uvs);
tc_physics_entity_s *physics_body = tc_get_pointer_from_entity(entity, "physics_body"); tc_physics_entity_s *physics_body = tc_get_pointer_from_entity(entity, "physics_body");
if(physics_body != 0)
{
tc_remove_physics_entity(physics_body); tc_remove_physics_entity(physics_body);
}
tc_deallocate_chunk(entity->specific); tc_deallocate_chunk(entity->specific);
} }

View File

@ -4,6 +4,7 @@
void tc_initialize_chunk_physics(tc_entity_s *chunk_entity, void *userdata) void tc_initialize_chunk_physics(tc_entity_s *chunk_entity, void *userdata)
{ {
/*
tc_chunk_s *chunk = chunk_entity->specific; tc_chunk_s *chunk = chunk_entity->specific;
tc_world_s *world = chunk->location.world; tc_world_s *world = chunk->location.world;
tc_physics_simulation_s *simulation = world->physics; tc_physics_simulation_s *simulation = world->physics;
@ -39,6 +40,7 @@ void tc_initialize_chunk_physics(tc_entity_s *chunk_entity, void *userdata)
tc_add_physics_object(world->physics, chunk_body); tc_add_physics_object(world->physics, chunk_body);
tc_set_pointer_for_entity(chunk_entity, "physics_body", chunk_body); tc_set_pointer_for_entity(chunk_entity, "physics_body", chunk_body);
*/
} }
void tc_create_world_physics(tc_world_s *world, void *userdata) void tc_create_world_physics(tc_world_s *world, void *userdata)