【发布时间】:2013-11-25 23:30:37
【问题描述】:
我一直在尝试让 xWinForms 3.0 库(xna 中支持表单的库)与我的 C# XNA 游戏项目一起使用,但我一直遇到同样的问题。 我添加对我的项目的引用,放入 using 语句,声明一个 formCollection 变量,然后尝试对其进行初始化。
每当我运行项目时,我都会停在这条线上:
formCollection = new FormCollection(this.Window, Services, ref graphics);
它给了我错误:
System.NullReferenceException 未处理 Message="Object 引用未设置为对象的实例。"
来源="Microsoft.Xna.Framework" StackTrace: 在 Microsoft.Xna.Framework.Graphics.VertexShader..ctor(GraphicsDevice 图形设备,字节 [] 着色器代码) 在 Microsoft.Xna.Framework.Graphics.SpriteBatch.ConstructPlatformData() 在 Microsoft.Xna.Framework.Graphics.SpriteBatch..ctor(GraphicsDevice 图形设备) 在 xWinFormsLib.FormCollection..ctor(GameWindow 窗口、IServiceProvider 服务、GraphicsDeviceManager 和图形) 在 C:\Users\Owner\Documents\School\Year 3\Winter\Soen 中的 GameSolution.Game2.LoadContent() 390\TeamWTF_3\SourceCode\GameSolution\GameSolution\Game2.cs:第 45 行 在 Microsoft.Xna.Framework.Game.Initialize() 在 C:\Users\Owner\Documents\School\Year 3\Winter\Soen 中的 GameSolution.Game2.Initialize() 390\TeamWTF_3\SourceCode\GameSolution\GameSolution\Game2.cs:第 37 行 在 Microsoft.Xna.Framework.Game.Run() 在 C:\Users\Owner\Documents\School\Year 3\Winter\Soen 中的 GameSolution.Program.Main(String[] args) 390\TeamWTF_3\SourceCode\GameSolution\GameSolution\Program.cs:第 14 行 内部异常:
在我下载的一个使用 xWinForms 的项目中,我将以下代码放入并编译并运行没有错误。 但是当我把它放在我的项目中时,我得到了错误。 我是否在包含 dll 或其他内容方面犯了一些愚蠢的错误?我已经在这里待了好几个小时,但我似乎找不到任何会导致这种情况的东西。
using xWinFormsLib;
public class Game2 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
FormCollection formCollection;
public Game2()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
// TODO: Add your initialization logic here
base.Initialize();
}
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
formCollection = new FormCollection(this.Window, Services, ref graphics);
}
protected override void Update(GameTime gameTime)
{
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
base.Draw(gameTime);
}
}
任何帮助将不胜感激。_。
【问题讨论】: