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

Fix buffering for events that have mapped entities. #321

Merged
merged 9 commits into from
Sep 3, 2024

Conversation

Shatur
Copy link
Contributor

@Shatur Shatur commented Sep 3, 2024

Closes #311.

@Shatur Shatur changed the title Do not panic on client event deserialization Do not panic on server event deserialization Sep 3, 2024
Copy link

codecov bot commented Sep 3, 2024

Codecov Report

Attention: Patch coverage is 64.55696% with 28 lines in your changes missing coverage. Please review.

Project coverage is 89.79%. Comparing base (3d48f5a) to head (b18ee8d).
Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
src/core/event_registry/server_event.rs 48.83% 22 Missing ⚠️
src/client/events.rs 87.87% 4 Missing ⚠️
src/core/ctx.rs 33.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #321      +/-   ##
==========================================
- Coverage   90.60%   89.79%   -0.82%     
==========================================
  Files          37       37              
  Lines        2300     2293       -7     
==========================================
- Hits         2084     2059      -25     
- Misses        216      234      +18     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +390 to +391
let event = (deserialize)(ctx, cursor);
if ctx.invalid_entities.is_empty() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should clear the invalid_entities in case multiple server events are received but only some of them are invalid.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right, good catch!

@Shatur Shatur requested a review from UkoeHB September 3, 2024 17:40
events.send(event);
}
Err(e) => error!(
"unable to deserialize independent event `{}`: {e}",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"unable to deserialize independent event `{}`: {e}",
"ignoring independent event `{}` from server that failed to deserialize: {e}",

@Shatur Shatur marked this pull request as ready for review September 3, 2024 18:16
@Shatur Shatur changed the title Do not panic on server event deserialization Fix buffering for events that have mapped entities. Sep 3, 2024
@Shatur Shatur requested a review from UkoeHB September 3, 2024 20:15
@Shatur
Copy link
Contributor Author

Shatur commented Sep 3, 2024

Fixed the bug reported by @NiseVoid in Discord.
Pushed it here since it touches the same code.

After the events refactor I map the event inside the deserialization function. But I need to deserialize the tick first and compare it for buffering. We didn't catch it in the tests because we didn't have a test for the combination of event buffering and entity mapping.

The fix is simple. The event queue is not generic now and stores the event in its serialized form. The resource now initialized inside the ClientPlugin. We deserialize the tick first, do comparsion and push the event to the queue if it's smaller.

registry: &registry.read(),
entity_map: &entity_map,
};
world.resource_scope(|world, mut queue: Mut<ServerEventQueue>| {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diff is messy, but I just added a new scope for ServerEventQueue.


let world_cell = world.as_unsafe_world_cell();
for event_data in event_registry.iter_server_events() {
// SAFETY: both resources mutably borrowed uniquely.
Copy link
Contributor Author

@Shatur Shatur Sep 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer need to be unsafe since we borrow only one resource and can get rid of the world cell.

@Shatur Shatur merged commit e98a940 into master Sep 3, 2024
6 checks passed
@Shatur Shatur deleted the avoid-client-event-panic branch September 3, 2024 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Do not panic on invalid entity mapping inside events
2 participants