Ruffles icon indicating copy to clipboard operation
Ruffles copied to clipboard

ReliableChannel stops receiving after 65535 packets

Open neto-kokku opened this issue 3 years ago • 7 comments

https://github.com/MidLevel/Ruffles/blob/378751e90c57e8359e2c032b37998950ecd69cbd/Ruffles/Channeling/Channels/ReliableChannel.cs#L60

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

neto-kokku avatar Sep 29 '21 22:09 neto-kokku

Good catch, thanks!

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

TwoTenPvP avatar Sep 30 '21 11:09 TwoTenPvP

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

The Ruffles project looks awesome! :)

collectVood avatar May 02 '23 13:05 collectVood

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

neto-kokku avatar May 02 '23 13:05 neto-kokku

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 😄

collectVood avatar May 02 '23 13:05 collectVood

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.

neto-kokku avatar May 02 '23 13:05 neto-kokku

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

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

collectVood avatar May 02 '23 14:05 collectVood

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

neto-kokku avatar May 02 '23 14:05 neto-kokku