UltravioletFramework / ultraviolet

The Ultraviolet Framework is a .NET game development framework written in C#.
https://github.com/UltravioletFramework/ultraviolet/wiki
MIT License
542 stars 46 forks source link

OverflowException SDL2 Applying FullScreenWindowed #109

Closed captkirk88 closed 5 years ago

captkirk88 commented 5 years ago
System.OverflowException : Arithmetic operation resulted in an overflow.
 at Ultraviolet.SDL2.Platform.SDL2UltravioletWindow.ApplyWin32FullscreenWindowedFix_FullscreenWindowed()
    at Ultraviolet.SDL2.Platform.SDL2UltravioletWindow.SetWindowMode(WindowMode mode)
    at Shared.Ultraviolet.Game.ApplySettings(Settings settings) in Game.cs:line 122
    at Shared.Ultraviolet.Game.OnLoadingContent() in Game.cs:line 58

Occurred after setting the FullScreenWindowed mode for the Primary window.

win.SetFullscreenDisplayMode(Ultraviolet.GetPlatform().Displays.PrimaryDisplay.DesktopDisplayMode);
win.SetWindowMode(UV.Platform.WindowMode.FullscreenWindowed);

That is also with the setting WindowIsShownImmediately set to false.

tlgkccampbell commented 5 years ago

I'm having difficulty reproducing this one.

My guess is that you're running a 32-bit process and on your system something is setting WS_POPUP on your window, which would cause its GWL_STYLE value to exceed the capacity of a signed 32-bit integer. But that doesn't seem to happen on my system.

At any rate I'm committing what I think should fix this exception and it should be available in the next release. I'll leave this issue open until we can confirm that it works for you.

tlgkccampbell commented 5 years ago

I've pushed the fix to NuGet as version 2019.2.0.3890. Please let me know if this resolves your issue.

captkirk88 commented 5 years ago

Same issue with the latest release off Nuget. I tried full Fullscreen mode and it works without any issues but FullscreenWindowed causes overflow. I'm curious if anyone else is having this problem. I have tried other engines like Libgdx, Jmonkey, MonoGame, UrhoSharp, Xenko, and a old build of OpenTK back when it was new. Never had this issue with SDL.

captkirk88 commented 5 years ago

Oh and it is in a NUnit test using x64 arch.

captkirk88 commented 5 years ago

Well, figured out the fix. For any future readers, set OpenGLUltravioletConfiguration#WindowIsBorderless to false. I get no overflow exceptions and the window displays with the FullScreenWindowed mode.

tlgkccampbell commented 5 years ago

The issue here isn't with SDL; there's some additional code around window state management that's specific to Ultraviolet, and there's a bug somewhere in the way that I'm passing values to the native Win32 API.

I'll try to reproduce this issue again later using the additional information that you've provided.

captkirk88 commented 5 years ago

If it helps more here is the exact configuration I was using including before I found the psuedo fix.

                Use32BitFramebuffer = false,
                UseBufferMapping = false,
                WindowIsBorderless = true,
                WindowIsResizable = false,
                MultiSampleSamples = 4,
                MultiSampleBuffers = 3,
                WindowIsShownImmediately = false,
                Headless = false,
                SupportsHighDensityDisplayModes = true

Not a ideal configuration for a normal game but mostly just fiddling with your engine.

tlgkccampbell commented 5 years ago

Thanks! I was able to reproduce locally. And thanks to that, I can confirm that my fixed worked.

...unfortunately, I also realized that I forgot to actually merge the fix into the master branch before updating the packages on NuGet, which is why updating your packages didn't actually fix anything. 😑

I'll push another hotfix through my build system.

tlgkccampbell commented 5 years ago

2019.2.0.3893 is live on NuGet and should actually contain the fix for this issue.