see the other post on headless monogame as well.
we want to be able to automatically enable headless compatibility using SDL2's video driver override feature (see the section on
SDL_VIDEODRIVER in the docs for envvar).
dummy driver seems to do what we need. and on the C# side, we prevent calling to any functionality that would fail when using the dummy driver.
also, if you avoid initializing the graphicsdevicemanager, at least with DesktopGL you can run headless by setting
SDL_VIDEODRIVER=dummy. For some reason it doesn't work when I use:
Environment.SetEnvironmentVariable("SDL_VIDEODRIVER", "dummy", EnvironmentVariableTarget.Process); at the start of the program.
However, it works when i run from the shell as
anyone have any idea why?
after doing some further work and messing around with P/Invoke, I finally solved the issue. I started off trying to bind SDL's native functions by using reflection to extract the MonoGame types that handle this (see the SDL2 method binder)
unfortunately, the function i wanted to use to set the environment variable,
SDL_putenv, appeared not to be available to bind for some reason.
objdump however, the symbols were exported:
the eventual fix that ended up working was using the abstract native interface to call the system
i initially had quite a bit of trouble getting the P/Invoke bindings to cooperate, but it turns out I had been using them wrong.
by looking at Mono.Posix's source, i was able to get the correct signature to P/Invoke.
revisit [day 2020-05-02]
it appears that i am dumb. i was looking to bind
objdump clearly shows that the two functions exported are
which means that i should in theory be able to bind the function that actually exists,
and just like that, we are able to bind those two functions (after updating the