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

ReliableChannel stops receiving after 65535 packets #34

Open
neto-kokku opened this issue Sep 29, 2021 · 7 comments
Open

ReliableChannel stops receiving after 65535 packets #34

neto-kokku opened this issue Sep 29, 2021 · 7 comments

Comments

@neto-kokku
Copy link

else if (sequence == _incomingLowestAckedSequence + 1)

This line here is missing the cast to ushort, causing the ReliableChannel to stop accepting packets past sequence 65535.

@TwoTenPvP
Copy link
Member

Good catch, thanks!

The design is meant to roll over. I will work on fixing this.

@collectVood
Copy link

Hey, has this been resolved yet or is there a work-around for it?

The Ruffles project looks awesome! :)

@neto-kokku
Copy link
Author

Just change the line to:
else if (sequence == (ushort)(_incomingLowestAckedSequence + 1))

@collectVood
Copy link

Ohhhh... I wasn't even aware that this could grow out of the ushort size like this. The more you know! Thanks a lot <3 😄

@neto-kokku
Copy link
Author

neto-kokku commented May 2, 2023

C# doesn't have short/ushort literals, so the 1 in the expression is an int. Adding an ushort to an int returns an int, and comparing an ushort to an int implicitly casts the ushort to int. So when _incomingLowestAckedSequence is 65535 (the largest value an ushort can hold) the addition results in 65536 instead of wrapping around back to 0.

This was a really annoying bug do fix since it manifested as the game simply breaking down after playing for over 20 minutes or so.

@collectVood
Copy link

This does make a lot of sense, you're right.

Glad you found it and shared it here to save everyone some time!

@neto-kokku
Copy link
Author

Here's a example where you can see this in action:
https://dotnetfiddle.net/dKKfaf

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

No branches or pull requests

3 participants