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 ReadUBits(32) masking out all bits. Thanks to @in0finite #56

Merged
merged 1 commit into from
Apr 12, 2024

Conversation

saul
Copy link
Owner

@saul saul commented Apr 12, 2024

Fixes #37

Copy link


BenchmarkDotNet v0.13.9+228a464e8be6c580ad9408e98f18813f6407fb5a, Ubuntu 22.04.4 LTS (Jammy Jellyfish)
AMD EPYC 7763, 1 CPU, 4 logical and 2 physical cores
.NET SDK 8.0.203
  [Host]     : .NET 8.0.3 (8.0.324.11423), X64 RyuJIT AVX2
  Job-IGJYAE : .NET 8.0.3 (8.0.324.11423), X64 RyuJIT AVX2
  Job-FVCKUP : .NET 8.0.3 (8.0.324.11423), X64 RyuJIT AVX2

InvocationCount=1  MaxIterationCount=16  UnrollFactor=1  
WarmupCount=1  

Method Job Arguments Mean Error StdDev Ratio Gen0 Gen1 Allocated Alloc Ratio
ParseDemo Job-IGJYAE /p:Baseline=true 2.263 s 0.0115 s 0.0096 s 1.00 5000.0000 2000.0000 489.9 MB 1.00
ParseDemo Job-FVCKUP Default 2.207 s 0.0241 s 0.0226 s 0.97 5000.0000 2000.0000 489.9 MB 1.00

@saul saul merged commit f8648e3 into main Apr 12, 2024
2 checks passed
@saul saul deleted the fix-position branch April 12, 2024 07:54
@@ -28,7 +41,7 @@ public uint ReadUBits(int numBits)
{

Choose a reason for hiding this comment

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

Can you please add a safeguard here, so it's easier to catch similar bugs :

#if DEBUG
if (numBits > 32 || numBits < 0)
    throw ...;
#endif

Copy link
Owner Author

Choose a reason for hiding this comment

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

This will throw as the code is already written

Choose a reason for hiding this comment

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

Maybe I am missing something, but if the code goes into else branch and if numBits is 50 and _bitsAvail is 32, it will not throw, but instead decrease numBits to 18.

Anyways, it's not intuitive as it is, so adding Debug.Assert() would not hurt.

@in0finite
Copy link

Could you also add a safeguard after reading all entities from BitBuffer here, to make sure everything is read from it:

if (entityBitBuffer.RemainingBytes >= 4)
    throw "not all data read";

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.

Pawn position is outside of buy-zone during freeze time
2 participants