gpt4 book ai didi

c# - AndroidGameWindow.SetDisplayOrientation NullReferenceException

转载 作者:可可西里 更新时间:2023-11-01 18:49:08 26 4
gpt4 key购买 nike

我使用 MonoGame 和 Xamarin 为 Android 开发了一款游戏。我将 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 是这样设置的:

[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 进行编译。我在我的测试设备上没有任何与方向相关的问题,所以我不确定是什么导致了这个异常,因此我无法修复它。

最佳答案

在处理另一个项目之前,我遇到过这个 Null Reference 异常。你将不得不原谅我对你的游戏领域的无知,但让我向你解释这意味着什么,也许它会帮助你解决这个问题。这个异常意味着内存中没有特定类型的对象可供系统处理。必须使用 new 关键字或以其他方式创建此对象的实例,才能将其识别为内存中的有效对象。

从阅读上面的错误消息来看,它似乎想要一个对象来初始化显示方向。在您的构造函数或 Activity 设置中,我看不到任何为显示方向创建任何对象的内容。因此该对象不在内存中,因此它为空。

关于c# - AndroidGameWindow.SetDisplayOrientation NullReferenceException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25654865/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com