Repository navigation
Voxels.bIsInside returns true for every point: bool return values in Interop.cs need MarshalAs(UnmanagedType.I1) #116
dl-eigenart
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Voxels.bIsInside(new in PicoGK 2, discussion #95) returnstruefor every point I give it, inside or outside, at every voxel size I tried (20, 5, 2, 1 and 0.5 mm), before and after boolean operations. The signed distance values in the field are fine at the same points, so the runtime knows where the surface is. The problem is in the C# declaration.Voxels_bIsInsidereturns a C++bool, one byte in AL. The declaration inInternals/Interop.cs(line 415) has noMarshalAs, so .NET reads the return as a four byte Win32 BOOL and treats anything non-zero as true. I called the same native function through three private declarations to see what actually comes back:Voxels.bIsInside[return: MarshalAs(UnmanagedType.I1)]Sphere R = 50 mm, 5 mm voxels. The low byte is correct, the upper three bytes are whatever was left in the register. With
I1marshalling the function is right at every point.ScalarField_bGetValueworks today only because the compiler happens to clear the full register there (raw EAX is a clean 0x00000000 / 0x00000001).Interop.cshas 26 extern declarations returningbooland 7boolparameters in extern signatures, none of them annotated. Which of them misbehave depends on the compiler and the platform, so I would fix all of them rather than the one I hit. A pull request with[return: MarshalAs(UnmanagedType.I1)]on the 26 returns and[MarshalAs(UnmanagedType.I1)]on the 7 parameters is here: #115. It changes 33 lines and nothing in the runtime.One caveat: I am on Linux (Ubuntu 25.10, runtime 26.2.0 built from
mainat 0f26321 with the Dockerfile from #77, PicoGK at 0e6cf6b). I know Linux is not a supported platform. But the missing annotation is the same on macOS and Windows; it just has not bitten anyone there yet, as far as I can tell.Repro is a single file,
dotnet run -- innen2 5: https://github.com/dl-eigenart/picogk-reproWould you prefer this as an issue on the PicoGK repo instead of a discussion?
All reactions