Я разработал игру для Android с помощью MonoGame и Xamarin. Я включил BugSense в него и быстро начал получать следующую трассировку стека исключений:
System.NullReferenceException: Object reference not set to an instance of an object
at Microsoft.Xna.Framework.AndroidGameWindow.SetDisplayOrientation (Microsoft.Xna.Framework.DisplayOrientation) <0x001c4>
at Microsoft.Xna.Framework.AndroidGameWindow.SetOrientation (Microsoft.Xna.Framework.DisplayOrientation,bool) <0x00097>
at Microsoft.Xna.Framework.OrientationListener.OnOrientationChanged (int) <0x001c7>
at Android.Views.OrientationEventListener.n_OnOrientationChanged_I (intptr,intptr,int) <0x0003f>
at (wrapper dynamic-method) object.ed9d7c7c-f3e6-4d7a-9249-1a139a251aed (intptr,intptr,int) <0x00043>
Вот как моя активность настраивается:
[Activity(Label = "My Cool Game"
, MainLauncher = true
, Icon = "@drawable/icon"
, Theme = "@style/Theme.Splash"
, AlwaysRetainTaskState = true
, LaunchMode = Android.Content.PM.LaunchMode.SingleTask
, ScreenOrientation = ScreenOrientation.Portrait
, ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.Keyboard | ConfigChanges.KeyboardHidden)]
И в конструкторе игры у меня есть следующее:
public Game1()
{
_graphics = new GraphicsDeviceManager(this);
_graphics.PreferredBackBufferFormat = SurfaceFormat.Color;
_graphics.IsFullScreen = true;
_graphics.SupportedOrientations = DisplayOrientation.Portrait | DisplayOrientation.PortraitDown;
_graphics.ApplyChanges();
}
Проект настроен на компиляцию с v2.3. У меня не было никаких проблем, связанных с ориентацией на моих тестовых устройствах, поэтому я не уверен, что вызывает это исключение, поэтому я не могу его исправить.