From a4f125f16e9ffb58123e1fb1c6a136dd66435e97 Mon Sep 17 00:00:00 2001 From: Stefanos A Date: Tue, 5 Nov 2013 23:21:49 +0100 Subject: [PATCH] Added workaround for issue #6 The issue is that some display devices report a BitsPerPel value of 0. It is not clear whether this is a bug in WinDisplayDevice.cs or some strange windows issue. The implemented workaround adds an entry to the debug log and hardcodes BitsPerPel to 32 whenever this condition is encountered. More investigation required. --- .../OpenTK/Platform/Windows/WinDisplayDevice.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Source/OpenTK/Platform/Windows/WinDisplayDevice.cs b/Source/OpenTK/Platform/Windows/WinDisplayDevice.cs index 511f8fb6..a22e1a56 100644 --- a/Source/OpenTK/Platform/Windows/WinDisplayDevice.cs +++ b/Source/OpenTK/Platform/Windows/WinDisplayDevice.cs @@ -122,6 +122,8 @@ namespace OpenTK.Platform.Windows if (Functions.EnumDisplaySettingsEx(dev1.DeviceName.ToString(), DisplayModeSettingsEnum.CurrentSettings, monitor_mode, 0) || Functions.EnumDisplaySettingsEx(dev1.DeviceName.ToString(), DisplayModeSettingsEnum.RegistrySettings, monitor_mode, 0)) { + VerifyMode(dev1, monitor_mode); + opentk_dev_current_res = new DisplayResolution( monitor_mode.Position.X, monitor_mode.Position.Y, monitor_mode.PelsWidth, monitor_mode.PelsHeight, @@ -134,6 +136,8 @@ namespace OpenTK.Platform.Windows mode_count = 0; while (Functions.EnumDisplaySettings(dev1.DeviceName.ToString(), mode_count++, monitor_mode)) { + VerifyMode(dev1, monitor_mode); + DisplayResolution res = new DisplayResolution( monitor_mode.Position.X, monitor_mode.Position.Y, monitor_mode.PelsWidth, monitor_mode.PelsHeight, @@ -163,6 +167,17 @@ namespace OpenTK.Platform.Windows } } + + static void VerifyMode(WindowsDisplayDevice device, DeviceMode mode) + { + if (mode.BitsPerPel == 0) + { + Debug.Print( + "[Warning] DisplayDevice '{0}' reported a mode with 0 bpp. Please create a bug report at http://www.opentk.com", + device.DeviceName.ToString()); + mode.BitsPerPel = 32; + } + } #endregion #region HandleDisplaySettingsChanged