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

Events<GamepadEventRaw> appears to be getting updated twice per world tick (gilrs) #2893

Closed
CAD97 opened this issue Sep 30, 2021 · 3 comments
Labels
A-Input Player input via keyboard, mouse, gamepad, and more C-Bug An unexpected or incorrect behavior 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

@CAD97
Copy link
Contributor

CAD97 commented Sep 30, 2021

Bevy version

git master

What you did

Looked at the code (I'm playing around with building a custom mini engine using bevy ECS, for learning purposes).

What you expected to happen

Events::update says it should be called once per tick, to manage the double buffer correctly.

What actually happened

update appears to be getting called twice per tick:

  • bevy_input calls add_event::<GamepadEventRaw>
    .add_event::<GamepadEventRaw>()

    and this registers the Event::update_system
    pub fn add_event<T>(&mut self) -> &mut Self
    where
    T: Component,
    {
    self.init_resource::<Events<T>>()
    .add_system_to_stage(CoreStage::First, Events::<T>::update_system)
    }
  • bevy_gilrs's gilrs_event_system calls event.update on the Events<GamepadEventRaw>
    pub fn gilrs_event_system(world: &mut World) {
    let world = world.cell();
    let mut gilrs = world.get_non_send_mut::<Gilrs>().unwrap();
    let mut event = world.get_resource_mut::<Events<GamepadEventRaw>>().unwrap();
    event.update();

Additional information

It's possible I'm just misunderstanding what's going on here, but this seems wrong at first glance. At the very least, the update call in bevy_gilrs probably deserves a comment calling out that it's a second update call in the simulation tick explaining why we want to discard the double buffer in this case.

@CAD97 CAD97 added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Sep 30, 2021
@alice-i-cecile alice-i-cecile added A-Input Player input via keyboard, mouse, gamepad, and more S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it! and removed S-Needs-Triage This issue needs to be labelled labels Sep 30, 2021
@alice-i-cecile
Copy link
Member

Good find. These events should not be cleared twice. Removing the update from gilrs is the correct way to fix this.

Incidentally, that system looks like it no longer need to be exclusive: we should fix that in the same PR.

@alice-i-cecile alice-i-cecile added the D-Trivial Nice and easy! A great choice to get started with Bevy label Sep 30, 2021
@CAD97
Copy link
Contributor Author

CAD97 commented Sep 30, 2021

AIUI systems that access non-send resources (like Gilrs is) still need to be exclusive. Or if they don't, I didn't find the correct way to request access.

@alice-i-cecile
Copy link
Member

Nope, they'll work fine in ordinary systems :) Just use NonSend as a system parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Input Player input via keyboard, mouse, gamepad, and more C-Bug An unexpected or incorrect behavior 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

Successfully merging a pull request may close this issue.

2 participants