Bug after Samsung update | Detecting viewport height as width


Got a android game coded in monogame, where i got a GraphicsDeviceManager which are set to FullScreen=true.

I use the GraphicsDevice.Viewport.Height and the GraphicsDevice.Viewport.Width to determine the resolution of the device.
This was working very good until i got an samsung update and had to turn FastDev off.
The big mysterious problem:

When i debug with the pc, the height and width of the viewport is set correct. But when i unplug and play the app after 1-2 times the viewport.Height becomes the devices width, and the viewport.Width becomes the device height, which completely makes the game unplayable.

Its very hard to find the solution, since this is never happening when i debug and got the cable in from pc to the device.

Anyone got any ideas what it can be?


I can now confirm that it is because of the samsung update


I made worlds simplest android app to test it, just got a mainframe with a background image called “bg” and a spritefront printing out the viewport.Width and viewport.Height.

Here’s the code:

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace TestRes

/// This is the main type for your game

public class Game1 : Microsoft.Xna.Framework.Game
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
SpriteFont font;
Rectangle _mainFrame;
Texture2D _background;
string text;

    public Game1()
        graphics = new GraphicsDeviceManager(this);

        Content.RootDirectory = "Content";

        graphics.IsFullScreen = true;
        //graphics.PreferredBackBufferWidth = 800;
       // graphics.PreferredBackBufferHeight = 480;
        graphics.SupportedOrientations = DisplayOrientation.LandscapeLeft;

    /// <summary>
    /// Allows the game to perform any initialization it needs to before starting to run.
    /// This is where it can query for any required services and load any non-graphic
    /// related content.  Calling base.Initialize will enumerate through any components
    /// and initialize them as well.
    /// </summary>
    protected override void Initialize()
        // TODO: Add your initialization logic here

        text = "";

    /// <summary>
    /// LoadContent will be called once per game and is the place to load
    /// all of your content.
    /// </summary>
    protected override void LoadContent()
        // Create a new SpriteBatch, which can be used to draw textures.
        spriteBatch = new SpriteBatch(GraphicsDevice);
        _background = Content.Load<Texture2D>("Bilder/bg");
        _mainFrame = new Rectangle(0, 0, this.GraphicsDevice.Viewport.Width, this.GraphicsDevice.Viewport.Height);
        // TODO: use this.Content to load your game content here
        font = Content.Load<SpriteFont>("spriteFont1");

    /// <summary>
    /// Allows the game to run logic such as updating the world,
    /// checking for collisions, gathering input, and playing audio.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Update(GameTime gameTime)
        if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
        text = "ScreenWidth: " + this.GraphicsDevice.Viewport.Width + ", screenheight: " + this.GraphicsDevice.Viewport.Height;
        // TODO: Add your update logic here


    /// <summary>
    /// This is called when the game should draw itself.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Draw(GameTime gameTime)

        spriteBatch.Draw(_background, _mainFrame, Color.White);
        spriteBatch.DrawString(font, text, new Vector2(16, 1000), Color.White);



When deploying from VS everything is good, the viewport.width is the actual device width and the viewport.height is the actual device height. But when trying to deploy it from the Samsung S4 (sometimes you need to try 2-3 times) then all of a sudden Viewport.Height is the device Width and the other way around, something makes the background picture just cover a bit of the screen.

Any monogame admins/developers who can take a look at it?

Pictures showing the problem

  1. When deploying from vs:
  2. After running on device BUG

Might be this same issue?

It definitely is!

Cant see anyone have come up with a good fix yet? This is a issue which needs to be adressed, many devices will encounter this problem when only allowed to run in DisplayOrientation.Landscape mode.

So to update:

The problem is if the app is only allowed to run in Landscape orientation, not when you use Portrait or both.

Fixed in pull request:

Ah nice!

Can se there is changes done in : MonoGame.Framework/Android/MonoGameAndroidGameView.cs and MonoGame.Framework/Graphics/GraphicsAdapter.cs to get this problem sorted, now i need to be a little dumb and ask: How do i find these classes in my VS project do make the changes? :open_mouth: Started using monogame for a couple of days ago, so still a newbie.

Download compiled MonoGame.Framework.dll from build server: http://teamcity.monogame.net/viewLog.html?buildId=1505&buildTypeId=MonoGame_DevelopMac&tab=artifacts#!1xyv
or checkout branch “kitkat_draw_shift” from my fork https://github.com/Andreyul/MonoGame and build from source.

When i am downloading the “Monogame.Framework.dll” under the folder IOS(There’s no android folder) in the link you gave me, and using that as a reference in the android project i am just getting

“The type or namespace name 'AndroidGameActivity” does not exist in the namespace ‘Microsoft.Xna.Framework’ (are you missing an assembly reference?)"

I compiled it for Android: https://dl.dropboxusercontent.com/u/21786859/MonoGame.Framework.dll

Thanks, it works :slight_smile: Now i am getting errors on following lines:

  1. Game1.Activity = this; (Property or indexer ‘Microsoft.Xna.Framework.Game.Activity’ cannot be assigned to – it is read only)
  2. SetContentView(g.Window); (Cannot convert from ‘Microsoft.Xna.Framework.GameWindow’ to ‘Android.Views.View’)

where g is the Game1 object.

  1. remove this line
  2. SetContentView(g.Services.GetService< View >());

Works like a charm, thanks man :smile:

One last question tho:

Since i am now using the MonoGame.Framework.dll you compiled for Android in my PCL project, will this be a problem when i am going to use the PCL code in my IOS project?