Identifying Windows resolution change at runtime

Trying a compiled project in a new windows powered tablet, which we were experimenting here, I noticed a problem anyone can try at a desktop Windows. In the tablet, all you have to do is rotate it, and the screen will flick.

To simulate it on a desktop windows, hold SHIFT before running the EXE and play it at full screen. CTRL+ESC out of it, right click on the desktop and open up Screen Resolution Windows Dialog. Set Orientation to anything other than the current one, press Apply, ALT+TAB back to the application.

The screen will flick a lot and if you wait for the 20 seconds for Windows to auto revert back to default settings, you’ll be able to see your app running normally back again.

Plus, under [APPLICATION]_Data folder the output_log.txt may have at least a line similar to the ones I get:

(Filename: C:/BuildAgent/work/842f9557127e852/Runtime/ExportGenerated/StandalonePlayer/UnityEngineDebug.cpp Line: 34)

Skipped rendering frame because GfxDevice is in invalid state (device lost)
 
(Filename: C:/BuildAgent/work/842f9557127e852/Runtime/Misc/Player.cpp Line: 1466)

D3D device reset failed [invalid call]
 
(Filename: C:/BuildAgent/work/842f9557127e852/Runtime/GfxDevice/d3d/D3D9Context.cpp Line: 456)

Skipped rendering frame because GfxDevice is in invalid state (device lost)

Any ideas on how to fix this?

i’ve kinda got the way to fix this - problem is that unity doesnt check how it’s oriented on focus, that means it still thinks it’s the same orientation, and gets Screen.height the same, despite that it becomes width. My problem was that I’ve got “resoulution checker” script, that tries to set corect resolution, and it worked wrong of course. So i’ve just got actual height and width of the screen using winAPI(user32.dll) directly, to find out actual orientation and correctly handle it.

If you start in windowed mode, you can use Screen.currentResolution to get the current desktop resolution. You can go into full screen with Screen.fullScreen.