From 0824ba109809991d2226b43574df835ccb39b1b6 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sun, 26 Jan 2020 01:31:40 +0100 Subject: [PATCH] added ApplyChangesSafely --- MLEM/Extensions/GraphicsExtensions.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/MLEM/Extensions/GraphicsExtensions.cs b/MLEM/Extensions/GraphicsExtensions.cs index a84e01a..e7b0097 100644 --- a/MLEM/Extensions/GraphicsExtensions.cs +++ b/MLEM/Extensions/GraphicsExtensions.cs @@ -11,8 +11,9 @@ namespace MLEM.Extensions { public static void SetFullscreen(this GraphicsDeviceManager manager, bool fullscreen) { manager.IsFullScreen = fullscreen; if (fullscreen) { - lastWidth = manager.GraphicsDevice.Viewport.Width; - lastHeight = manager.GraphicsDevice.Viewport.Height; + var view = manager.GraphicsDevice.Viewport; + lastWidth = view.Width; + lastHeight = view.Height; var curr = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode; manager.PreferredBackBufferWidth = curr.Width; @@ -27,5 +28,15 @@ namespace MLEM.Extensions { manager.ApplyChanges(); } + public static void ApplyChangesSafely(this GraphicsDeviceManager manager) { + // If we don't do this, then applying changes will cause the + // graphics device manager to reset the window size to the + // size set when starting the game :V + var view = manager.GraphicsDevice.Viewport; + manager.PreferredBackBufferWidth = view.Width; + manager.PreferredBackBufferHeight = view.Height; + manager.ApplyChanges(); + } + } } \ No newline at end of file