Skip to content

SDL3 on Emscripten 3.1.56 #25404

@LloydJHowarth

Description

@LloydJHowarth

⁸I have a .NET 9 wasm-tools project running SDL2 working flawlessly with no problems at all however I'm trying to shift towards SDL3. As of right now .NET 9 wasm-tools projects are locked at Emscripten 3.1.56 but I've noticed an SDL3 port in version 4.0.15 therefore I backported it to run with 3.1.56.

However I couldn't include this code from the sdl3.py file

def process_dependencies(settings, cflags_only):
if not cflags_only:
# SDL3 includes an internal reference to Module['createContext']
settings.EXPORTED_RUNTIME_METHODS.append('createContext')

Emscripten 3.1.56 doesn't seem to have anything to handle this so I'm unsure what to do so for now I just removed the code and built. I even tried adding it the same way sdl2.py handles its export methods etc with no luck. Anyway.. this outputs a libSDL3.a file that I then used in my project. Everything works as expected such as SDL Initialized, SDL Events and anything else SDL related can be called with no issues, except creating a window.

When I run this code

Console.WriteLine("Attempting to initialize");
if(SDL_Init(SDL_InitFlags.SDL_INIT_VIDEO | SDL_InitFlags.SDL_INIT_AUDIO)) Console.WriteLine("SDL Initialized");

Console.WriteLine("Attempting to create window");
window = SDL_CreateWindow("Hi", 400, 400, 0);
if(window == IntPtr.Zero) Console.WriteLine("Failed to create window");

Console.WriteLine("Attempting to create renderer");
renderer = SDL_CreateRenderer(window, null);
if(renderer == IntPtr.Zero) Console.WriteLine("Failed to create renderer");

This is the output:

Attempting to initialize
dotnet.native.hzzryi8u7q.js:1819 SDL Initialized
dotnet.native.hzzryi8u7q.js:1819 Attempting to create window
dotnet.native.wasm-04a64d1e:0x115bcd Uncaught RuntimeError: null function or function signature mismatch
at dotnet.native.wasm.do_icall (dotnet.native.wasm-04a64d1e:0x115bcd)
at dotnet.native.wasm.do_icall_wrapper (dotnet.native.wasm-04a64d1e:0x111f43)
at dotnet.native.wasm.mono_interp_exec_method (dotnet.native.wasm-04a64d1e:0x103197)
at dotnet.native.wasm.interp_runtime_invoke (dotnet.native.wasm-04a64d1e:0x11344e)
at dotnet.native.wasm.mono_jit_runtime_invoke (dotnet.native.wasm-04a64d1e:0x232430)
at dotnet.native.wasm.do_runtime_invoke (dotnet.native.wasm-04a64d1e:0x1f23c0)
at dotnet.native.wasm.mono_runtime_try_invoke (dotnet.native.wasm-04a64d1e:0x1f2e40)
at dotnet.native.wasm.mono_runtime_invoke (dotnet.native.wasm-04a64d1e:0x1f5a64)
at dotnet.native.wasm.mono_wasm_invoke_jsexport (dotnet.native.wasm-04a64d1e:0x3b06de)
at dotnet.native.hzzryi8u7q.js:811:12

As you can see SDL3 is being called as expected but windows aren't working. I've even checked the exported functions and SDL_CreateWindow is definitely there. I've tried SDL_CreateWindowAndRenderer as well but no luck. Obviously createContext is required but I just can't seem to handle it with 3.1.56

I dont really have in depth knowledge of Emscripten, wasm, etc. I'm just porting my existing working SDL2 project to SDL3 and this is where I'm at right now. Everything works but window creation. Unfortunately I think .NET users will be stuck on Emscripten 3.1.56 for a few years to come. Maybe till even .NET 12 so we are pretty much locked at SDL2...

Is there anything that can be done to solve this issue and create a window / context?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions