Open stanoddly opened 1 year ago
It might be possible to get this to work by using the previous approach we used for callbacks though not ideal. Do you know any details about why this is not supported?
It's mentioned in blazor docs:
Here is the link to the issue: https://github.com/dotnet/runtime/issues/56145
I think this example shows the complete workaround that works for me.
The main idea is to wrap method address into the unmanaged delegate and then cast to IntPtr:
// emscripten_wrap.c: Native lib with callback propagation, actually wrapper over statically linked emscriptent
// to be able to use it with [DllImport]
// See https://github.com/dotnet/runtime/discussions/81991#discussioncomment-5009635
#include <emscripten.h>
EMSCRIPTEN_KEEPALIVE
void call_emscripten_set_main_loop(em_callback_func func, int fps, int simulate_infinite_loop)
{
emscripten_set_main_loop(func, fps, simulate_infinite_loop);
}
// Bindings, note the IntPtr pointer type here
public class Emscripten
{
[DllImport("emscripten_wrap", CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe void call_emscripten_set_main_loop(IntPtr callback, int fps, int simulateInfiniteLoop);
}
// Callback definition
static readonly delegate* unmanaged<void> CallbackPointer = &Callback;
[UnmanagedCallersOnly]
public static void Callback()
{
// ...
}
// Callback setup
public static void SetupCallback()
{
Emscripten.call_emscripten_set_main_loop((IntPtr)CallbackPointer , 0, 1);
}
P.S. Thank you for this titanic work with bringing Raylib-cs
to the WASM environment, I'm also stepping through this road and your examples saved me really a huge amount of time!
The build returns lots of these warnings, which means that this functionality can't be used as it is.