dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.56k stars 4.54k forks source link

Parameter types of pinvoke callback method 'System.Int32 _PDG(Silk.NET.SDL.PfnMallocFunc, Silk.NET.SDL.PfnCallocFunc, Silk.NET.SDL.PfnReallocFunc, Silk.NET.SDL.PfnFreeFunc)' needs to be blittable. #102644

Open smaybius opened 1 month ago

smaybius commented 1 month ago

Description

Whenever I try building a browser app that uses native assemblies or references a project that does, it errors out with Parameter types of pinvoke callback method 'System.Int32 _PDG(Silk.NET.SDL.PfnMallocFunc, Silk.NET.SDL.PfnCallocFunc, Silk.NET.SDL.PfnReallocFunc, Silk.NET.SDL.PfnFreeFunc)' needs to be blittable.

Reproduction Steps

Expected behavior

Builds like normal

Actual behavior

That error pointing to WasmApp.Native.Targets

Regression?

No

Known Workarounds

None

Configuration

.NET 8, Windows 11, x64, Avalonia web project, no browser involved (build error)

Other information

No response

Perksey commented 1 month ago

This is related to #61146, which was closed with a partial fix: to my knowledge, unmanaged structs are still considered not blittable unless the declaring assembly has disabled runtime marshalling. Silk.NET has not done this, primarily because we’d have to ifdef that given our support for NS20 and our assessment was that going through this effort wasn’t strictly necessary as, given that we were using blittable bindings already, there would be no difference.

Pfn prefixed structures contain a single void* field. We changed this from being a function pointer field to workaround another mono bug, but the details there have been lost to time.

If it is the team’s assessment that unmanaged structures are not considered blittable then we’d be happy to ifdef in the next Silk.NET update.