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

[wasm] Attempting to get an EventWriter for an unregistered event type panics with an unhelpful message #2139

Closed
lukewestby opened this issue May 10, 2021 · 5 comments
Labels
A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Trivial Nice and easy! A great choice to get started with Bevy S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it!

Comments

@lukewestby
Copy link

lukewestby commented May 10, 2021

Bevy version

0.5.0

Operating system & version

wasm

What you did

Create a system like so:

struct Event;

fn system(mut events: EventWriter<Event>) {}

Set up the app, but do not register the event

App::build()
    .with_system(system.system())
    .run();

What you expected to happen

The application is misconfigured so I expect this to panic, and ideally the message for the panic would explain that a system attempted to fetch an EventWriter for an unregistered event type.

What actually happened

The application panics with the following:

panicked at 'assertion failed: `(left == right)`
  left: `true`,
 right: `false`: cannot recursively acquire mutex',

and upon further examination of the stack trace it turns out to be the failure described by #1924

@lukewestby lukewestby added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels May 10, 2021
@alice-i-cecile alice-i-cecile added C-Usability A targeted quality-of-life change that makes Bevy easier to use A-ECS Entities, components, systems, and events and removed S-Needs-Triage This issue needs to be labelled labels May 10, 2021
@alice-i-cecile
Copy link
Member

FYI you don't need to register the event with add_event, merely create a resource for it. I agree that the error message should be much better though.

@NiklasEi
Copy link
Member

NiklasEi commented May 10, 2021

FYI you don't need to register the event with add_event, merely create a resource for it.

Adding the resource would remove this particular error, but the event would not be functioning without the managing system (added e.g. via add_event), would it?
Since events are used a lot, could we maybe make this a custom error pointing to add_event? On Linux I just get "thread 'main' panicked at 'Requested resource does not exist: bevy_app::event::Eventsstream::Event'" which could be nicer in my opinion if it were more event specific.

@alice-i-cecile
Copy link
Member

alice-i-cecile commented May 10, 2021

Adding the resource would remove this particular error, but the event would not be functioning without the managing system (added e.g. via add_event), would it?

It will work just fine, it'll just lack automatic cleanup. This pattern is actually quite useful for when you need events to function for systems that sleep (like if they operate on a fixed time step); you just need to handle cleaning them up on your own so the memory use doesn't grow in an unbounded fashion.

I'm working on an EventConsumer API over in #2116 to make that more ergonomic and better documented. It'll probably get split out into a separate PR for scope though.

Since events are used a lot, could we maybe make this a custom error pointing to add_event? On Linux I just get "thread 'main' panicked at 'Requested resource does not exist: bevy_app::event::Eventsstream::Event'" which could be nicer in my opinion if it were more event specific.

Agreed, although it should also point to .init_resource::<T> as well.

@alice-i-cecile alice-i-cecile added D-Trivial Nice and easy! A great choice to get started with Bevy and removed C-Bug An unexpected or incorrect behavior labels Dec 12, 2021
@alice-i-cecile
Copy link
Member

Cleaning up the error messages here would be a nice step forward, and should be quite approachable for a new contributor.

@alice-i-cecile alice-i-cecile added the S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it! label Dec 12, 2021
@CGMossa
Copy link
Contributor

CGMossa commented Jun 30, 2022

I recommend we close this;
A similar issue is #5088, and it was decided there to close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Trivial Nice and easy! A great choice to get started with Bevy S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it!
Projects
None yet
Development

No branches or pull requests

4 participants