Skip to content

Unmanaged Callbacks marshal bool return values incorrectly #9

@NoelFB

Description

@NoelFB

Really nice bindings!

The unmanaged callbacks that use bool return values are marshalled incorrectly, as C# assumes they are 4-byte values. In some cases it may be fine with this, but in others it will crash.

[DllImport(BindgenInternal.DllImportPath, EntryPoint = "b2World_SetPreSolveCallback")]
public static extern void WorldSetPreSolveCallback(WorldId worldId, delegate* unmanaged<ShapeId, ShapeId, Manifold*, void*, bool> fcn, void* context);

This can be easily fixed by changing the return value to a byte instead of a bool, but it does mean you have to manually return a byte when implementing the callbacks. There may be a way to use the [MarshalAs] attribute here, but I'm not sure how to with these unmanaged function pointers.

[DllImport(BindgenInternal.DllImportPath, EntryPoint = "b2World_SetPreSolveCallback")]
public static extern void WorldSetPreSolveCallback(WorldId worldId, delegate* unmanaged<ShapeId, ShapeId, Manifold*, void*, byte> fcn, void* context);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions