You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Make a new game from the desktopgl template: dotnet new mgdesktopgl -o MyGame
On Game1.cs:45, change the drawing code so we can get some visual feedback on the state of Game.IsActive: GraphicsDevice.Clear(IsActive ? Color.CornflowerBlue : Color.OrangeRed);
Launch the game (dotnet run or a build), then quickly at tab to some other window and click on it to give it focus.
Here it is behind a chrome window, for example:
It's blue, showing that IsActive is true even though we have never given the window focus.
Tabbing in and then out correctly turns the window red, as IsActive is now correctly false.
I've seen several google results for this bug going back years, but none of the commonly quoted solutions actually fix the problem (checking window handles, registering our own events, etc). it would be awesome if this could be fixed at the source
@Apostolique recommended including this SDL2 file, and doing this workaround:
This fixes the bug: is it possible monogame could check this way instead? Currently it's listening to events, which means it misses the initial loss of focus before the app has fully started.
for anyone still tracking this issue, the SDL workaround fixed it BUT it made it so one players game simply never thought it had focus. i haven't been able to track down anything different about their setup, but this bug does still exist in 3.8.1.303
For anyone like me who finds this issue and follows @Apostolique's suggestion above to fix it: The SDL2.cs file linked has unsafe functions in it. I needed to add this to my .csproj file for it to compile without erroring:
The repro steps for this are quick:
Make a new game from the desktopgl template:
dotnet new mgdesktopgl -o MyGame
On
Game1.cs:45
, change the drawing code so we can get some visual feedback on the state ofGame.IsActive
:GraphicsDevice.Clear(IsActive ? Color.CornflowerBlue : Color.OrangeRed);
Launch the game (dotnet run or a build), then quickly at tab to some other window and click on it to give it focus.
Here it is behind a chrome window, for example:
It's blue, showing that
IsActive
is true even though we have never given the window focus.Tabbing in and then out correctly turns the window red, as
IsActive
is now correctly false.I've seen several google results for this bug going back years, but none of the commonly quoted solutions actually fix the problem (checking window handles, registering our own events, etc). it would be awesome if this could be fixed at the source
@Apostolique recommended including this SDL2 file, and doing this workaround:
https://github.com/flibitijibibo/SDL2-CS/blob/master/src/SDL2.cs
This fixes the bug: is it possible monogame could check this way instead? Currently it's listening to events, which means it misses the initial loss of focus before the app has fully started.
MonoGame/MonoGame.Framework/Platform/SDL/SDLGamePlatform.cs
Lines 218 to 223 in 2fa5961
The text was updated successfully, but these errors were encountered: