Possible out-by-one bug in GraphicsDevice.Viewport

Before I raise this as a bug in github I wanted to check opinions here. Maybe it has always been like this, or is a “feature” inherited from XNA, but it certainly seems wrong to me. I’m using the 3.3 release.

GraphicsDevice.Viewport is reporting a width and height that are 1 pixel too small.

For example: on my Surface Pro 3, the default resolution is 2160x1440 but GraphicsDevice.Viewport.Width = 2159 and .Height=1439

TitleSafeArea is reporting the same figures.

Now, I’d expect bounds.Right to be 2159 and .Bottom to be 1439 as these are the “last pixels” - but the width and height should be the “whole numbers”. Just because we are zero-indexed doesn’t mean the width and height should be 1 pixel shorter than they actually are.

This problem is ruining my graphics scaling… I could compensate for it easily enough, but frankly I think this is wrong and would rather it was right at source (and so I’m not going to get any surprises when MonoGame fixes this in the future).

hi,

I’ve noticed this problem in WP8 too for a long time (not a 3.3 exclusive problem) but never paid much attention because it didn’t give me problems. Honestly, I don’t know if it’s a bug or a windows feature :slight_smile:

I think I found the real problem. It’s in MetroGameWindow.cs / SetClientBounds , pwidth and pheight gives a 1919.99999 value instead of 1920, which casted to int it’s still a 1919. Replacing the cast with a Math.Round or something like this should give the correct resolutions.

I just updated to the latest monogame repository and found that the problem was already fixed :slight_smile:

1 Like

Cheers, that’s good news. I’ll grab the latest and go from there.