Can emplace as callback of on_destroy break? #648
-
I have a tag (
Later in the code, I periodically iterate over all entities having
Note, this is similar to observers, but:
However, I just catch a bug where So, I am currently suspicious about the process of destroying an entity. Is the following scenario possible?
If that is so, do you have any suggestion how I could fix it on my end? One way I see I could do it, is, instead of having a tag Other solution? In |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
The destruction of an entity expects that you don't add components to the same entity in a callback. The registry triggers an assert in debug mode if this happens, while it's UB in release.
A quick and dirty solution is to replace the destroy with something like:
Otherwise, you can use a dedicate sparse set rather than a pool that is managed by the registry, then test if its entities are valid. This will filter out destroyed entities. It would also help if you could describe what you're trying to do. Maybe someone can come up with a better suggestion. 👍 |
Beta Was this translation helpful? Give feedback.
The destruction of an entity expects that you don't add components to the same entity in a callback. The registry triggers an assert in debug mode if this happens, while it's UB in release.
So, well, yeah, this is definitely possible. 🙂
A quick and dirty solution is to replace the destroy with something like: