bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Is the "event not consumed" warning spurious?

Open alice-i-cecile opened this issue 3 years ago • 3 comments

Discussed in https://github.com/bevyengine/bevy/discussions/6595

Originally posted by nicopap November 13, 2022

Missed 31 `bevy_input::mouse::MouseMotion` events. Consider
reading from the `EventReader` more often (generally the best
solution) or calling Events::update() less frequently
(normally this is called once per frame). This problem is most
likely due to run criteria/fixed timesteps or consuming events
conditionally. See the Events documentation for
more information.

Live example: https://nicopap.github.io/bevy_mod_paramap/earth3d.html (open console, drag around the glob by holding middle click down)

Source code is: https://github.com/nicopap/bevy_mod_paramap/blob/7c5d9789ddd3cb05eb1b023cc0bab0aa5cfa021c/examples/earth3d.rs#L232-L308

I'm getting a warning when I'm doing something quite normal. I just do not read the MouseMotion event when I don't need to.

The error says This problem is […] due to […] consuming events conditionally but fails to explain why it is an issue. Looking at the Events doc, I don't see much of an argument against reading events conditionally.

It feels like a very common false positive. This is very confusing to a new user, especially given most of the warning message doesn't at all match what I'm actually doing in my code. In fact I do often skip reading events when I don't need to read them (for performance!) and I've seen this error in a lot of my projects.

I understand why it can help, but did we not forget to weight the cost of false positives when adding this feature? The likely thing I'll do next time I see this error is to just ignore it, and it might as well not exist in this case.

  • PR introducing the message: https://github.com/bevyengine/bevy/pull/5730

alice-i-cecile avatar Nov 13 '22 21:11 alice-i-cecile

I think we should probably just revert this PR: the false positive cost is very high and it adds an extra branching check that will rarely be useful.

alice-i-cecile avatar Nov 13 '22 21:11 alice-i-cecile

This happens while doing, what I believe, is normal handoff of input from game to egui and back. For example, if egui_context.ctx_mut().wants_pointer_input() I conditionally stop reading events.

rozgo avatar Nov 14 '22 01:11 rozgo

Yep, I ran into exactly that problem. The error can be useful, but it has some nasty false positives, spams hard, and is really challenging to figure out how to silence.

alice-i-cecile avatar Nov 14 '22 02:11 alice-i-cecile

I'm also getting a large number of these warnings after upgrading to 0.9. The ones that get the highest number of "missed" events seem to be from systems that only run during certain states, and produce warnings with a number of missed events that is higher depending on how long it was since that state was active - sometimes in the 1000s - whenever the state becomes active. Outside of these, there also seem to be some more frequent ones due to deliberately skipping reading events in various systems based on cooldowns or other conditions making them irrelevant for that update cycle.

As far as I can tell, all of these warnings are irrelevant and caused by things that are working as intended.

I suppose there might, at least theoretically be cases where this warning actually indicates an error, if you accidentally omit reading from an event reader or return early from a system when it was not intended, but as far as I can see, this would be extremely rare and niche compared to the vast number of false positives produced.

forbjok avatar Nov 16 '22 21:11 forbjok

If you miss events for a bit and then read them again, you're going to get the events for this frame and the previous. Probably fine in many cases but could definitely be a source for some weird bugs. https://github.com/bevyengine/rfcs/pull/17 might be a step in the right direction.

I'm okay with removing the warning for now though as there's no nice way to handle this currently.

tim-blackbird avatar Nov 22 '22 19:11 tim-blackbird