Minimizing game makes screen blue

So, I have my Windows Monogame Direct X project with not much going on.
I’m just drawing some sprites and I have implemented some UI elements with the nice Empty Keys library.

Everytime I minimize the game window and re-open it, the screen becomes the default cornflowe blue color and it doesn’t change back.

This is the code in my Draw method:


    //Empty Keys stuff


    Vector2 cardPosition = new Vector2(400, 50);
    this.spriteBatch.Draw(texture: this.testCard, position: cardPosition, scale: new Vector2(0.5f));

    Vector2 stageLayoutOrigin = this.stageLayout.Bounds.Center.ToVector2();
    Vector2 playAreaOrigin = this.playArea.Center.ToVector2();

    this.spriteBatch.Draw(texture: this.stageLayout, position: playAreaOrigin , origin: stageLayoutOrigin, color: Color.White);



I’m using a Nividia GeForce graphics card and Monogame 3.5.

I have confirmed that this does not happen if I create a new blank MonoGame Windows project and draw a picture there.

I also use the PreparingDeviceSettings event for settings:

private void Graphics_PreparingDeviceSettings(object sender, PreparingDeviceSettingsEventArgs e)
{ = true; = GraphicsProfile.HiDef; = true; = DepthFormat.Depth24Stencil8;

    e.GraphicsDeviceInformation.PresentationParameters.MultiSampleCount = 16;

Sounds like an issue with Focus, but not one I’ve come across before.

Raise it as an issue on the GitHub page and likely one of the team will respond there.

Try develop before opening an issue, it might have been fixed. I think this might be an EmptyKeys issue though.

Also you’re using the PreparingDeviceSettings event wrong. You should either set stuff in GraphicsDeviceManager before the device is created or if you want to use the event set the presentation parameters passed with the event arguments.

1 Like

@JJag As for preparing device settings, I copied this one from the tutorial for Empty Keys UI.
I don’t really understand what the event is supposed to do, so I was afraid to change it because maybe it breaks something from EmptyKeysUI.

The way it works is when a device is created, the event is triggered and the event argument is a GraphicsDeviceInformation object (which is just GraphicsProfile and PresentationParams) populated with settings from the GraphicsDeviceManager like preferred backbuffer width/height, multisampling settings and so on. If you listen for the event you can override any of these settings. After the event, the settings from the GraphicsDeviceInformation from the event is used to create a new GraphicsDevice. So you can choose to either set what you want in GraphicsDeviceManager or override it in the event. It’s a bit quirky, but we follow XNA behaviour in this. I like to think of setting the stuff in GraphicsDeviceManager to be permanent, but not absolute since it can be overridden and doing it in the event as a one-timer (and remove the handler after the event is triggered). It’s really up to you how you handle it though, either works as long as you don’t set GDM stuff in the event handler.

SynchronizeWithVerticalRetrace and PreferMultiSampling are true by default. EmptyKeys might require a HiDef profile for some effects (I don’t know much about it really). I usually set the GraphicsProfile to HiDef in the Game constructor when I require it. I don’t think any other of the things done in the function you posted are required for it to work.

Anyway, this isn’t related to your issue :confused: Maybe you can open an issue on the EmptyKeys/UI_Engines GitHub page?

Anyway, this isn’t related to your issue

Yes, it is. Because I just made the issue disappear by removing the “PreparingDeviceSetting” event handler.

I put the former content of the handler in the constructor, except I removed MultiSampleCount, SynchronizeWithVerticalRetrace and PreferMultiSamling. The last two I removed because you said they were true by default.

Oh, I didn’t expect that… Weird. :stuck_out_tongue: Though maybe it is a MonoGame bug then… But great that it solved your issue!

Might still be an EmptyKeys issue if it is also using the “PreparingDeviceSetting” event. Not sure in which order they would be executed between your project and EmptyKeys.
Another stab in the dark to maybe explain why.

Not looked in to the Empty Keys source for some time, so might be worth checking out.