Skip to content

Can emplace as callback of on_destroy break? #648

Answered by skypjack
LiliumAtratum asked this question in Q&A
Discussion options

You must be logged in to vote
  • This triggers on_destroy, which now adds Collector tag to the entity in the middle of its destruction process.
  • The destruction of an entity does not notice that Collector was added (is that possible?)
  • entity is destroyed. But Collector storage still has an entry of that non-existent entity.

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. 🙂

If that is so, do you have any suggestion how I could fix it on my end?

A quick and dirty solution is to replace the destroy with something like:

registry.remove_…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@LiliumAtratum
Comment options

@Innokentiy-Alaytsev
Comment options

@LiliumAtratum
Comment options

@skypjack
Comment options

Answer selected by LiliumAtratum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants