alecthomas / entityx

EntityX - A fast, type-safe C++ Entity-Component system
MIT License
2.23k stars 295 forks source link

Commented the assertion, as it prevents adding components to an entry… #173

Closed onatbas closed 7 years ago

onatbas commented 7 years ago

… in a loop of entities_with_components

When looping through entitites with entities_with_components, this assertion prevents the assignments to the entity. Such as this:

ComponentHandle<Box> boxHandle;
for (auto entity: entitiy_manager.entities_with_components(boxHandle))
{
    entity.assign<BoxPosition>();
}

It might be the design intention, but I wanted to create a pull request in case it isn't and I found the possible quick solution.

FrankStain commented 7 years ago

@onatbas , this code may cause the memory leak. This assert may not be removed, as far as i know.

The reason you can't add the components is because the entity already contain the requested component.

alecthomas commented 7 years ago

@FrankStain is correct. This assert is intentional. If you want to add the component if it's missing, you'll need to check for its existence first.