In use-after-despawn situation, make despawning system name available#2949
Closed
payload wants to merge 3 commits intobevyengine:mainfrom
Closed
In use-after-despawn situation, make despawning system name available#2949payload wants to merge 3 commits intobevyengine:mainfrom
payload wants to merge 3 commits intobevyengine:mainfrom
Conversation
payload
commented
Oct 10, 2021
| std::borrow::Cow::Borrowed(s) => s, | ||
| std::borrow::Cow::Owned(_) => "owned", | ||
| }; | ||
| Commands::new(state, world).with_name(name) |
Contributor
Author
There was a problem hiding this comment.
I should just pass the Cow here 🐄 . It is in both cases cheap, right?
payload
commented
Oct 10, 2021
| std::borrow::Cow::Borrowed(s) => s, | ||
| std::borrow::Cow::Owned(_) => "owned", | ||
| }; | ||
| Commands::new(state, world).with_name(name) |
Contributor
Author
There was a problem hiding this comment.
Maybe it would be more appropriate to pass the whole SystemMeta, but well, I can't figure out the lifetime specifiers. And maybe the lifetime is not even guaranteed since the Despawn command, lands in a queue and the later the SystemMeta would land in some kind of buffer for the whole stage.
payload
commented
Oct 10, 2021
| impl Command for Despawn { | ||
| fn write(self, world: &mut World) { | ||
| println!("despawn from {}", self.name); | ||
| world.set_system_name(Some(self.name)); |
Contributor
Author
There was a problem hiding this comment.
This set name thing is crude. I am sorry. It may could be a separate despawn* function on world instead which takes the despawn origin name.
Member
|
Closing as #3851 was merged :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This draft sketches a debugging help in a situation where a command like
Insertacts upon an entity which was already despawned. When the command is applied it will panic with the messageThis tells which component (String) should have been added to which Entity (0v0) together with a hint that some system order dependency exist and is off.
To debug a situation like this one question would be "Which system was despawning this entity?" but this question might not be easy to answer.
A related issue and PR is
Commanderror handling #2241 but configurable error handling does not help in debugging the issue nor can it be easily be used in the case where the panicing system is a third party systemSolution
The panic message should contain the name of the system which despawned the entity, so when debugging I can immediately jump to this system, schedule it in a different stage or delay the despawn:
In this case
use_after_despawn::do_despawnis the fully qualified name of the systemdo_despawn.The implementation extents
Commandswith a system name (if it is a static str).When
Despawn(orDespawnRecursive) is added to the queue the struct carries on this system name.When
Despawn::writeis run, it is setting some crude system name state on the world.When
EntityRef::despawnis run, it looks up the system name from the world and adds this entity and this name to aWorld::despawnedvec.This vec is cleared at the beginning of every stage (ignoring use cases without stages).
When a panic happens due to a missing entity during a
Command::write, you can now look up the entity in theWorld::despawnedvec and put the system name in the panic message.