You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 12, 2021. It is now read-only.
Found this problem while wanting to remove a component of an entity, when that entity was added to a new system.
Here's my understanding of the problem:
a. |onEntityAdded| is called while iterating over |m_entityCache.activated|.
b. Calling activate() leads to adding an entry to |m_entityCache.activated|.
Unfortunately, iterating on a vector that you modify doesn't work.
Possible fix:
Copy (or swap pointers/std::move) all the arrays over which you iterate at the beginning of World::refresh(), clear them, and only then iterate over them:
void World::refresh() {
auto copyActivated = m_entityCache.activated;
auto copyDeactivated = m_entityCache.deactivated;
auto copyKilled = m_entityCache.killed;
m_entityCache.clearTemp();
for (auto& entity : copyActivated) {
The text was updated successfully, but these errors were encountered:
Hm, just commented on #82 mentioning this. I thought having an assert to forbid calling activate from within refresh might do. it'd be simple to add, and if you (like me) still would want to activate entities from onEntityAdded, one would have to implement a temporary storage for those entities in own code. i'd prefer that cause i would want to be in control of when i actually need that overhead, as only a few refresh-calls actually have activates in them (at least for me).
Found this problem while wanting to remove a component of an entity, when that entity was added to a new system.
Here's my understanding of the problem:
a. |onEntityAdded| is called while iterating over |m_entityCache.activated|.
b. Calling activate() leads to adding an entry to |m_entityCache.activated|.
Unfortunately, iterating on a vector that you modify doesn't work.
Possible fix:
Copy (or swap pointers/std::move) all the arrays over which you iterate at the beginning of World::refresh(), clear them, and only then iterate over them:
The text was updated successfully, but these errors were encountered: