Skip to content

Load SDL3 when using SDL_image or SDL_ttf #213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

smoogipoo
Copy link
Contributor

Startup fails because the native SDL3 lib isn't loaded:

dlopen(/Users/smgi/Desktop/SDLImageTest/SDLImageTest/bin/Debug/net8.0/runtimes/osx-arm64/native/libSDL3_ttf.dylib, 0x0001): Library not loaded: @rpath/libSDL3.0.dylib
  Referenced from: <86C0A333-AD6F-3D99-8F4E-186F20B256BE> /Users/smgi/Desktop/SDLImageTest/SDLImageTest/bin/Debug/net8.0/runtimes/osx-arm64/native/libSDL3_ttf.dylib
  Reason: no LC_RPATH's found

Calling SDL3.SDL_Init(0) fixes this and relies on the .NET library resolution mechanism.

@smoogipoo smoogipoo requested a review from Susko3 June 19, 2025 16:56
@smoogipoo smoogipoo changed the title Load SDL3 when using SDL_image or SDL_ttf members Load SDL3 when using SDL_image or SDL_ttf Jun 19, 2025
@WizzardMaker
Copy link
Contributor

I would caution against using the ModuleInitializer to load other libraries as a library.
Depending on the environment (various Windows versions) this can lead to potentially lock up the application due to the LoadLibrary loader lock

What would be the scenario in which SDL helper libraries were to be executed before SDL? Afaik SDL needs to be initialized before calling any function on helper libraries anyway

Could this be solved by a static constructor for these classes instead?

public static unsafe partial class SDL3_ttf {
    static SDL3_ttf() {
        SDL3.SDL_Init(0);
    }
}

@smoogipoo
Copy link
Contributor Author

I came up with this PR because I was looking at examples, but I must have missed the SDL_Init() call because...

Afaik SDL needs to be initialized before calling any function on helper libraries anyway

This does appear to be the case indeed. Will close this for now then :)

I would caution against using the ModuleInitializer to load other libraries as a library.

Good call, I'll be keeping this one in mind.

@smoogipoo smoogipoo closed this Jun 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants