-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
[Merged by Bors] - Fix Events::<drain/clear> bug #2206
[Merged by Bors] - Fix Events::<drain/clear> bug #2206
Conversation
cb71e4d
to
598196b
Compare
Thanks! This is a nice thing to pull over. |
Good call. Looks like |
bors r+ |
Taken from #2145 On draining, `Events` did not reset it's internal event count members.
bors r- |
Canceled. |
Hmm one issue to discuss that I discovered when putting together my followup: Resetting |
@cart I'll add this fix to the PR as well.
Hmm yes this does seem to be incorrect... |
Yep adding this: events.send(E(1));
let _ = events.drain();
assert_eq!(reader.iter(&events).next(), None); in the tests causes it to fail. |
Is that with or without the "fix" above? Adding that passes with the fix for me. |
@cart, a possible solution: |
With your change included. #[test]
fn test_events_drain() {
#[derive(PartialEq, Eq, Debug)]
struct E(usize);
let mut events = Events::<E>::default();
let mut reader = events.get_reader();
assert!(reader.iter(&events).next().is_none());
events.send(E(0));
assert_eq!(reader.iter(&events).next(), Some(&E(0)));
assert_eq!(reader.iter(&events).next(), None);
events.send(E(1));
let _ = events.drain();
assert_eq!(reader.iter(&events).next(), None);
events.send(E(2));
events.send(E(3));
assert_eq!(reader.iter(&events).next(), Some(&E(2)));
assert_eq!(reader.iter(&events).next(), Some(&E(3)));
assert_eq!(reader.iter(&events).next(), None);
} |
Found another corner case. Adding an #[test]
fn test_events_drain() {
#[derive(PartialEq, Eq, Debug)]
struct E(usize);
let mut events = Events::<E>::default();
let mut reader = events.get_reader();
assert!(reader.iter(&events).next().is_none());
events.send(E(0));
assert_eq!(*reader.iter(&events).next().unwrap(), E(0));
assert_eq!(reader.iter(&events).next(), None);
let _ = events.drain();
assert!(reader.iter(&events).next().is_none());
events.send(E(1));
events.update();
events.send(E(2));
assert_eq!(*reader.iter(&events).next().unwrap(), E(1));
assert_eq!(*reader.iter(&events).next().unwrap(), E(2));
} |
I'm gonna keep working through my PR review queue. If you find a fix definitely do it for clear() too 😄 I'll check back in later / help out if it hasn't been sorted out yet. |
@cart it turns out our last
This is how the test should be structured... #[test]
fn test_events_drain() {
// test stuff
events.send(E(1));
events.update();
events.send(E(2));
let mut iter = reader.iter(&events);
assert_eq!(*iter.next().unwrap(), E(1));
assert_eq!(*iter.next().unwrap(), E(2));
} |
Bahaha whoops. Nice catch! |
598196b
to
c623cc4
Compare
Co-authored-by: Alice Cecile <[email protected]>
c623cc4
to
8b1abbb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good; factoring out that logic reduces the risk of bugs in the future.
@cart I have this current implementation which passed the failing test we set up. |
bors r+ |
Taken from #2145 On draining and clearing, dangling `EventReaders` would not read into the correct event offset.
Pull request successfully merged into main. Build succeeded: |
Taken from bevyengine#2145 On draining and clearing, dangling `EventReaders` would not read into the correct event offset.
Taken from #2145
On draining and clearing, dangling
EventReaders
would not read into the correct event offset.