Skip to content

Commit

Permalink
Merge PR #2460 by @flo - memory leak fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
Cervator committed Sep 9, 2016
2 parents a7aa0a2 + 85acd27 commit 8cce02c
Showing 1 changed file with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -380,16 +380,29 @@ public EntityRef createEntityRefWithId(long id) {
return EntityRef.NULL;
}

/**
* Creates the entity without sending any events. The entity life cycle subscriber will however be informed.
*/
@Override
public EntityRef createEntityWithoutLifecycleEvents(Iterable<Component> components) {
return createEntity(components);
EntityRef entity = createEntity(components);
for (Component component: components) {
notifyComponentAdded(entity, component.getClass());
}
return entity;
}

/**
* Creates the entity without sending any events. The entity life cycle subscriber will however be informed.
*/
@Override
public EntityRef createEntityWithoutLifecycleEvents(String prefabName) {
return createEntityWithoutLifecycleEvents(getPrefabManager().getPrefab(prefabName));
}

/**
* Creates the entity without sending any events. The entity life cycle subscriber will however be informed.
*/
@Override
public EntityRef createEntityWithoutLifecycleEvents(Prefab prefab) {
if (prefab != null) {
Expand All @@ -405,9 +418,13 @@ public EntityRef createEntityWithoutLifecycleEvents(Prefab prefab) {
}
}

/**
* Destroys the entity without sending any events. The entity life cycle subscriber will however be informed.
*/
@Override
public void destroyEntityWithoutEvents(EntityRef entity) {
if (entity.isActive()) {
notifyComponentRemovalAndEntityDestruction(entity.getId(), entity);
destroy(entity);
}
}
Expand Down Expand Up @@ -538,13 +555,17 @@ public void destroy(long entityId) {
eventSystem.send(ref, BeforeDeactivateComponent.newInstance());
eventSystem.send(ref, BeforeRemoveComponent.newInstance());
}
notifyComponentRemovalAndEntityDestruction(entityId, ref);
destroy(ref);
}

private void notifyComponentRemovalAndEntityDestruction(long entityId, EntityRef ref) {
for (Component comp : store.iterateComponents(entityId)) {
notifyComponentRemoved(ref, comp.getClass());
}
for (EntityDestroySubscriber destroySubscriber : destroySubscribers) {
destroySubscriber.onEntityDestroyed(ref);
}
destroy(ref);
}

private void destroy(EntityRef ref) {
Expand Down

0 comments on commit 8cce02c

Please sign in to comment.