Skip to content

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

Closed

Description

@lukewestby

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

Activity

  1. added
    C-BugAn unexpected or incorrect behavior
    S-Needs-TriageThis issue needs to be labelled
    on May 10, 2021
  2. added
    C-UsabilityA targeted quality-of-life change that makes Bevy easier to use
    A-ECSEntities, components, systems, and events
    and removed
    S-Needs-TriageThis issue needs to be labelled
    on May 10, 2021
  3. alice-i-cecile commented on May 10, 2021

    @alice-i-cecile
    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.

  4. NiklasEi commented on May 10, 2021

    @NiklasEi
    Member

    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.

  5. alice-i-cecile commented on May 10, 2021

    @alice-i-cecile
    Member

    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.

  6. added
    D-TrivialNice and easy! A great choice to get started with Bevy
    and removed
    C-BugAn unexpected or incorrect behavior
    on Dec 12, 2021
  7. alice-i-cecile commented on Dec 12, 2021

    @alice-i-cecile
    Member

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

  8. CGMossa commented on Jun 30, 2022

    @CGMossa
    Contributor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-UsabilityA targeted quality-of-life change that makes Bevy easier to useD-TrivialNice and easy! A great choice to get started with BevyS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions