Skip to content

Commit

Permalink
replace most SDL_SetHint calls with SDL_SetHintWithPriority
Browse files Browse the repository at this point in the history
ensures calls actually do something and won't be ignored due to env vars
  • Loading branch information
CasualPokePlayer committed Oct 30, 2024
1 parent 9f3630c commit 6578c85
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/BizHawk.Bizware.Graphics/OpenGL/SDL2OpenGLContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static SDL2OpenGLContext()
// make sure that Linux uses the x11 video driver
// we need this as mono winforms uses x11
// and the user could potentially try to force the wayland video driver via env vars
SDL_SetHint("SDL_VIDEODRIVER", "x11");
SDL_SetHintWithPriority("SDL_VIDEODRIVER", "x11", SDL_HintPriority.SDL_HINT_OVERRIDE);
// try to use EGL if it is available
// GLX is the old API, and is the more or less "deprecated" at this point, and potentially more buggy with some drivers
// we do need to a bit more work, in case EGL is not actually available or potentially doesn't have desktop GL support
Expand Down Expand Up @@ -97,10 +97,10 @@ static SDL2OpenGLContext()

// we will be turning a foreign window into an SDL window
// we need this so it knows that it is capable of using OpenGL functions
SDL_SetHint(SDL_HINT_VIDEO_FOREIGN_WINDOW_OPENGL, "1");
SDL_SetHintWithPriority(SDL_HINT_VIDEO_FOREIGN_WINDOW_OPENGL, "1", SDL_HintPriority.SDL_HINT_OVERRIDE);
// don't allow windows events to be pumped
// it's not needed and can be dangerous in some rare cases
SDL_SetHint(SDL_HINT_WINDOWS_ENABLE_MESSAGELOOP, "0");
SDL_SetHintWithPriority(SDL_HINT_WINDOWS_ENABLE_MESSAGELOOP, "0", SDL_HintPriority.SDL_HINT_OVERRIDE);
}

#if DEBUG_OPENGL
Expand Down
2 changes: 1 addition & 1 deletion src/BizHawk.Bizware.Input/SDL2/SDL2InputAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static SDL2InputAdapter()
{
SDL_SetEventFilter(_sdlEventFilter, IntPtr.Zero);
// this is required as we create hidden (unfocused!) SDL windows in IGL backends
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
SDL_SetHintWithPriority(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1", SDL_HintPriority.SDL_HINT_OVERRIDE);
}

private static void DoSDLEventLoop()
Expand Down
2 changes: 1 addition & 1 deletion src/BizHawk.Client.EmuHawk/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ private static int SubMain(string[] args)
// if this isn't done, SIGINT/SIGTERM get swallowed by SDL
if (OSTailoredCode.IsUnixHost)
{
SDL2.SDL.SDL_SetHint(SDL2.SDL.SDL_HINT_NO_SIGNAL_HANDLERS, "1");
SDL2.SDL.SDL_SetHintWithPriority(SDL2.SDL.SDL_HINT_NO_SIGNAL_HANDLERS, "1", SDL2.SDL.SDL_HintPriority.SDL_HINT_OVERRIDE);
}

var glInitCount = 0;
Expand Down

4 comments on commit 6578c85

@Morilli
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is a response to some broken behavior? I just wonder what could go wrong with the previous code in case this could come up elsewhere or later again.

@CasualPokePlayer
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #1430 (comment)

Env vars have SDL_HINT_OVERRIDE priority, so simple SDL_SetHint calls won't affect them.

@Morilli
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm alright, but is this the "correct" thing to do then? Like should we be forcefully ignoring env vars that set SDL hints?

@CasualPokePlayer
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For cases where it doesn't make sense to allow the user to override the setting regardless (and potentially will just lead to broken behavior if our hints are not respected) sure.

Please sign in to comment.