codingben / box2d-netstandard

C# port of Box2D - Erin Catto's 2D Physics Engine
https://box2d.org
MIT License
271 stars 53 forks source link

Null Reference Exceptions when running #4

Closed HughPH closed 4 years ago

HughPH commented 4 years ago

I fixed these and somehow the files went walkabout.

In summary, in some places structs are expected, and that's fine in the C++ code because they're accessed by reference. In C#, when an item is picked from an array and it's a value type (e.g. a struct), what you get is a copy. The upshot is that mutating the object mutates the copy that you got, and not the item in the array. As a consequence, I had to use classes for several types. And a knock-on effect is that they then must be explicitly instantiated with the new keyword.