You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are many const T* parameters in Box2D. The easy way is to treat all of them as ref, i.e. not caring about the const part. However, this not only causes unnecessary friction when using the methods, such as the need to declare parameters on a separate line (you can just supply a value to an in parameter), but also loses the readonly intention of the pointer. It may be more correct to expose these pointers as in instead of ref.
Since you translate constant struct pointers that have an associated count to ReadOnlySpan instead of Span, constant struct pointers that only point to one item should be translated as in instead of ref too.
It seems that some functions that only take readonly parameters, like b2CollideCircles are now a mix of in and ref, which is weird. I thought that const T* meant in and regular parameters stay as regular parameters.
So inconsistent... Some Id parameters use in and others not. Do you really need to pass a B2ShapeId which is the size of a long by ref? The resulting size is the same on 64-bit operating systems but now you have indirection.
Activity
Happypig375 commentedon Nov 11, 2025
Since you translate constant struct pointers that have an associated count to ReadOnlySpan instead of Span, constant struct pointers that only point to one item should be translated as
ininstead ofreftoo.ikpil commentedon Dec 14, 2025
Sorry for the late reply.
I completely agree with what you mentioned.
I’ll make the changes that can be adjusted accordingly.
Happypig375 commentedon Feb 26, 2026
It seems that some functions that only take readonly parameters, like b2CollideCircles are now a mix of
inandref, which is weird. I thought thatconst T*meantinand regular parameters stay as regular parameters.Box2D.NET/src/Box2D.NET/B2Manifolds.cs
Line 45 in 31376f3
Happypig375 commentedon Feb 26, 2026
So inconsistent... Some Id parameters use
inand others not. Do you really need to pass aB2ShapeIdwhich is the size of alongby ref? The resulting size is the same on 64-bit operating systems but now you have indirection.ikpil commentedon Feb 28, 2026
Thank you for letting me know. If anything is missing, please let me know. I will review it and make the necessary updates.
ikpil commentedon Feb 28, 2026
#85
Happypig375 commentedon Feb 28, 2026
It is also for
B2PolygoninB2Manifolds.cs.ikpil commentedon Apr 5, 2026
I applied this change, but I’m getting a compiler warning.
The issue occurs when accessing an internal array from a readonly struct passed with in.
Although the struct is treated as readonly, arrays are reference types and their elements remain mutable, which causes the compiler warning.