Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize DiagnosticStore on register_diagnostic if it does not exist #8819

Merged
merged 3 commits into from
Jun 12, 2023
Merged

Initialize DiagnosticStore on register_diagnostic if it does not exist #8819

merged 3 commits into from
Jun 12, 2023

Conversation

opstic
Copy link
Contributor

@opstic opstic commented Jun 11, 2023

Objective

Solution

  • Call init_resource on register_diagnostic so that a DiagnosticStore gets initialized if it does not exist.

Copy link
Contributor

@nicopap nicopap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a tricky behavior. Now, the user could forget to add the DiagnosticsPlugin without a panic.

So we have the choice between:

code adds register_diagnostic before DiagnosticsPlugin forgets to add DiagnosticsPlugin but yet uses register_diagnostic
main panics panics
#8819 runs runs
bevy Bug in user code? Conscequences
panics yes user is annoyed, learn from panic message what the issue is and fixes it
runs yes user encounters a mysterious bug they have no idea how to fix, spend 2 hours fixing it
panics no user is annoyed, spend 2 hours trying to fix it, submits a bug to bevy when they figure out it originates from bevy
runs no user is happy 🎉

Honestly I think it's better to panic too much than not enough, so I think this should be solved differently.

Here is a suggestion: use get_reflect_mut over reflect_mut in line 307. Do

let Some() = …get_resource_mut()  else {
   panic!("Add DiagnosticsPlugin _before_ calling register_diagnostic, or something");
};

@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior C-Examples An addition or correction to our examples A-Diagnostics Logging, crash handling, error reporting and performance analysis X-Controversial There is active debate or serious implications around merging this PR labels Jun 11, 2023
@nicopap
Copy link
Contributor

nicopap commented Jun 11, 2023

@mockersf what do you think? You suggested this change.

@alice-i-cecile alice-i-cecile requested a review from mockersf June 11, 2023 16:32
@mockersf
Copy link
Member

mockersf commented Jun 11, 2023

This is a tricky behavior. Now, the user could forget to add the DiagnosticsPlugin without a panic.

Well... to be honest, I would suggest nuking the DiagnosticsPlugin completely. Its sole purpose is adding the resource (and also log system info), which is meaningless if you don't register a diagnostic. So the important part is registering a diagnostic, not adding the plugin which adds an empty resource, and it makes sense for me to move the focus from the plugin to the actual diagnostic.

That said, let's keep the plugin for now because it may make sense for diagnostics created during runtime.

I'm not sure how to read your tables, but registering a diagnostic before adding the DiagnosticPlugin, or even without adding it, will have zero impact / bug / anything. It will just work with this PR.

Co-authored-by: François <[email protected]>
@nicopap
Copy link
Contributor

nicopap commented Jun 11, 2023

I'm not sure how to read your tables

My concern was that the user would forget to add DiagnosticsPlugin, expect the behaviors from DiagnosticsPlugin and not see them and be surprised.

I didn't realize DiagnosticsPlugin doesn't add much behavior (so it's easy to know what is broken and how to fix it if you forgot to add DiagnosticsPlugin). In which case I think it's better to not fail if the user adds the diagnostics before the plugin.

@nicopap nicopap removed the X-Controversial There is active debate or serious implications around merging this PR label Jun 11, 2023
@opstic opstic requested a review from mockersf June 11, 2023 18:37
@mockersf mockersf added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Jun 11, 2023
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jun 12, 2023
Merged via the queue into bevyengine:main with commit 2b4fc10 Jun 12, 2023
@opstic opstic deleted the insert-diagnostic-when-not-found branch June 13, 2023 03:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Diagnostics Logging, crash handling, error reporting and performance analysis C-Bug An unexpected or incorrect behavior C-Examples An addition or correction to our examples S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

many_sprites and many_animated_sprites crashing on initialization
4 participants