-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
EventReader iter can skip events if interrupted #1157
Comments
|
For the use pattern outlined in my example, I'm fine manually updating the Events, rather than using the double buffer from |
The "bug" in your code is that you fail to process events on the frame (or the frame after) they were produced. I think the crux of this issue is that you would prefer event queues with unbounded allocations. The "double buffered" approach we use by default ensures that if events are not processed within a given frame (or the frame after), they will be freed / not take up space in the queue. I think this is a desirable default for most events because users won't process most events by default. It keeps the total allocations and the cost of readers low. From an efficiency perspective I think the current approach is basically optimal for games. And the "you must handle events each frame" constraint is pretty reasonable imo. Every other major engine has the same constraints, they just have a different interface (ex: register an event handler for a specific event type instead of using a system). There will be some cases where unbounded event queues are desirable, but its the sort of thing you need to specifically code around, otherwise you risk allocating memory ad-infinitum. |
But adding an option to "pop off" a single event (for a given reader) sounds like a reasonable add. |
Yeah, I did a bunch more digging into this after filing an issue. I was trying to use Bevy's events as if they were consuming, whereas they by default work on a observing / pub-sub / double buffer paradigm. Adding a couple of methods to |
This can be resolved with |
Bevy version
0.4
Operating system & version
Ex: Windows 10, Ubuntu 18.04, iOS 14.
What you did
Ran the example here: https://github.com/alice-i-cecile/understanding-bevy/blob/afe2d7dff009037f2f272c0dff18fab14af64aa2/src/ecs/systems-queries_code/examples/concurrency.rs
What you expected to happen
Each event should be processed in order.
What actually happened
Most events are skipped, because the system runs out of time to process them and
EventReader.iter()
updates its internal counter all the way to the end of the current queue. This is documented but is surprising behavior that is likely generally unhelpful.Additional information
Exposing the current length of the EventReader would also be helpful for similar tasks :)
The text was updated successfully, but these errors were encountered: