Crash when changing screen resolution
See original GitHub issueWPF application using MahApp MetroWindow crashes with unhandled exception when reducing screen resolution and the window width and height properties are defined.
Problem occurs on remote desktop environments when connecting with different clients (screen resolutions) to terminal servers.
Steps to reproduce the behavior:
Following simple xaml has been used to reproduce the behavior:
<Metro:MetroWindow x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:Metro="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Background="WhiteSmoke"
Title="MainWindow"
Height="768"
Width="1024">
<Grid>
</Grid>
</Metro:MetroWindow>
- Open the app on a high resolution (3840x2160 and 150% text size) screen and maximize the window.
- Reduce the resolution of the screen while app is maximized to 1024x768
- Minimize the application and the application will crash with an unhandled exception
Detailed windbg exception information:
0:000> !pe
Exception object: 0248cc60
Exception type: System.ArgumentException
Message: Width and Height must be non-negative.
InnerException: <none>
StackTrace (generated):
<none>
StackTraceString: <none>
HResult: 80070057
0:000> !CLRStack
OS Thread Id: 0x12d4 (0)
Child SP IP Call Site
004ddc10 748a5ef8 [HelperMethodFrame: 004ddc10]
004ddcc0 6c8a204e System.Windows.Rect..ctor(Double, Double, Double, Double)
004ddcec 69696cd4 System.Windows.Window.GetNormalRectDeviceUnits(IntPtr)
004ddd68 69696d22 System.Windows.Window.GetNormalRectLogicalUnits(IntPtr)
004ddde0 696964aa System.Windows.Window.get_RestoreBounds()
004dddf0 69696f31 System.Windows.Window.UpdateDimensionsToRestoreBounds()
004dde2c 6a3dee8c System.Windows.Window.WmSizeChanged(IntPtr)
004dde90 6970c4dc System.Windows.Window.WindowFilterMessage(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
004ddeb4 6a8e9703 System.Windows.Interop.HwndSource.PublicHooksFilterMessage(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
004ddee8 6c60c28b MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
004ddf24 6c60c1db MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
004ddf34 6c60c062 System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
004ddf54 6c60bfa4 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
004ddf98 6c60a581 System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
004ddff4 6c60baae MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)
004de4b8 005ed0b9 [InlinedCallFrame: 004de4b8] MS.Win32.UnsafeNativeMethods.CallWindowProc(IntPtr, IntPtr, Int32, IntPtr, IntPtr)
004de4b4 6c60c380 MS.Win32.HwndSubclass.DefWndProcWrapper(IntPtr, Int32, IntPtr, IntPtr)
004de628 005ed0b9 [InlinedCallFrame: 004de628]
004de624 6c63939e DomainBoundILStubClass.IL_STUB_PInvoke(IntPtr, IntPtr, Int32, IntPtr, IntPtr)
004de628 6c60bae9 [InlinedCallFrame: 004de628] MS.Win32.UnsafeNativeMethods.CallWindowProc(IntPtr, IntPtr, Int32, IntPtr, IntPtr)
004de664 6c60bae9 MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)
004debe0 005ed0b9 [InlinedCallFrame: 004debe0] MS.Win32.UnsafeNativeMethods.CallWindowProc(IntPtr, IntPtr, Int32, IntPtr, IntPtr)
004debdc 6c60c380 MS.Win32.HwndSubclass.DefWndProcWrapper(IntPtr, Int32, IntPtr, IntPtr)
004ded50 005ed0b9 [InlinedCallFrame: 004ded50]
004ded4c 6c63939e DomainBoundILStubClass.IL_STUB_PInvoke(IntPtr, IntPtr, Int32, IntPtr, IntPtr)
004ded50 6c60bae9 [InlinedCallFrame: 004ded50] MS.Win32.UnsafeNativeMethods.CallWindowProc(IntPtr, IntPtr, Int32, IntPtr, IntPtr)
004ded8c 6c60bae9 MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)
004def34 005ed0b9 [InlinedCallFrame: 004def34]
004def30 6c639678 DomainBoundILStubClass.IL_STUB_PInvoke(System.Windows.Interop.MSG ByRef)
004def34 6c60857d [InlinedCallFrame: 004def34] MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)
004def68 6c60857d System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)
004defb4 6c60816e System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame)
004defc0 696a4eca System.Windows.Application.RunDispatcher(System.Object)
004defd0 696a4d60 System.Windows.Application.RunInternal(System.Windows.Window)
004deff0 696a4b07 System.Windows.Application.Run(System.Windows.Window)
004df000 696a46e4 System.Windows.Application.Run()
004df00c 0065049c WpfApp1.App.Main()
004df188 7093ebb6 [GCFrame: 004df188]
Screenshots
Environment:
- MahApps.Metro v1.6.5
- OS: Windows Server 2012 R2
- Visual Studio 2017 15.9.2
- .NET Framework 4.6.1
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Games Crash When Changing Resolution: 4 Quick Ways ...
1. Uninstall conflicting applications · 2. Disable display scaling and run in compatibility mode · 3. Manually change the resolution file · 4....
Read more >My game crashes Everytime I try to change resolution ...
Once you've changed it to 1920x1080, go back into the game files and change it back to full screen.
Read more >PC Black Screen Crashing when I try to change Resolution ...
My Computer crashes when I try to change Resolution & Refresh Rate or when I try to run most programs in full screen,...
Read more >Game crash when i change resolution - Linus Tech Tips
when i try to play i game whit another resolution then my moitors standar resolution. the game just tabs out and keep on...
Read more >Different Resolution= game crash?
2) Changing the resolution CAN also cause a game to crash if it's stressing your graphics card more and it's unstable (perhaps insufficient ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
We currently use a workaround that detects the screen resolution change and sets window state to normal and immediately to maximized afterwards if the app is maximized in code behind file “MainWindow.xaml.cs”.
I’m closing this issue because it has been inactive for a few months. This probably means that it is not reproducible or it has been fixed in a newer version. If it’s an enhancement and hasn’t been taken on for so long, then it seems no one has the time to implement this.
Please reopen if you still encounter this issue with the latest stable version and then please use the issue template.
If you have enough time then it would be nice to test this issue against the latest alpha version (availabe via NuGet and appveyor).
Thank you! 🙏