Fixed issues and bugs

-moved system destroy functionality to System structure "destroy()" function
-now arrays are properly destroyed (with destructor calling (__xdtor))
-fixed bug which makes BlockAllocator crashing after freeing it's memory
-fixed many smaller memory leaks
This commit is contained in:
Mergul 2020-07-17 13:34:08 +02:00
parent 74179b4fc8
commit 96bbcb9956
5 changed files with 87 additions and 39 deletions

View file

@ -96,29 +96,7 @@ export struct EntityManager
{
foreach (ref system; systems)
{
system.disable();
if (system.m_destroy)
(cast(void function(void*)) system.m_destroy)(system.m_system_pointer);
if (system.jobs)
Mallocator.dispose(system.jobs);
if (system.m_read_only_components)
Mallocator.dispose(system.m_read_only_components);
if (system.m_writable_components)
Mallocator.dispose(system.m_writable_components);
if (system.m_components)
Mallocator.dispose(system.m_components);
if (system.m_excluded_components)
Mallocator.dispose(system.m_excluded_components);
if (system.m_optional_components)
Mallocator.dispose(system.m_optional_components);
if (system.m_name)
Mallocator.dispose(system.m_name);
if (system.m_event_callers)
Mallocator.dispose(system.m_event_callers);
if (system.m_system_pointer)
Mallocator.dispose(system.m_system_pointer);
system.destroy();
}
foreach (EntityInfo* info; &entities_infos.byValue)
@ -425,7 +403,8 @@ export struct EntityManager
enum EventName = fullName!(Unqual!(EventParamType));
// enum EventName = fullyQualifiedName!(Unqual!(EventParamType));//.stringof;
ushort evt = events_map.get(cast(char[]) EventName, ushort.max);
assert(evt != ushort.max, "Can't register system \"" ~ SystemName
assert(evt != ushort.max,
"Can't register system \"" ~ SystemName
~ "\" due to non existing event \"" ~ EventName ~ "\".");
callers[i].callback = cast(void*)&callEventHandler!(EventParamType);
@ -1188,10 +1167,9 @@ export struct EntityManager
ushort sys_id = systems_map.get(cast(char[]) SystemName, ushort.max);
if (sys_id < systems.length)
{
systems[sys_id].disable();
if (systems[sys_id].m_destroy)
(cast(void function(void*)) systems[sys_id].m_destroy)(
systems[sys_id].m_system_pointer);
system.m_name = systems[sys_id].m_name;
systems[sys_id].m_name = null;
systems[sys_id].destroy();
if (system.m_create)
(cast(void function(void*)) system.m_create)(system.m_system_pointer);
@ -1199,7 +1177,6 @@ export struct EntityManager
system.enable();
system.m_id = sys_id;
system.m_name = systems[sys_id].m_name;
systems[sys_id] = system;
}
else
@ -1307,6 +1284,8 @@ export struct EntityManager
if (comp_id < components.length)
{
Comp.component_id = comp_id;
if (components[comp_id].init_data)
Mallocator.dispose(components[comp_id].init_data);
components[comp_id] = info;
}
else
@ -1874,7 +1853,8 @@ export struct EntityManager
foreach (i, id; ids)
{
if(current_delta == 0)current_delta = ushort.max;
if (current_delta == 0)
current_delta = ushort.max;
alignNum(current_delta, components[id].alignment);
info.deltas[id] = cast(ushort) current_delta;
current_delta += entites_in_block * components[id].size;
@ -3548,6 +3528,10 @@ export struct EntityManager
Mallocator.dispose(deltas);
if (tmpl_deltas)
Mallocator.dispose(tmpl_deltas);
if (comp_add_info)
Mallocator.dispose(comp_add_info);
if (comp_rem_info)
Mallocator.dispose(comp_rem_info);
if (systems)
Mallocator.dispose(systems);
if (add_listeners)