2010-04-05 53 views
0

我一直在嘗試使用我的C#XNA Game項目來獲取xWinForms 3.0庫(xna中具有表單支持的庫),但我一直在獲取同樣的問題。 我將引用添加到我的項目中,放入using語句中,聲明一個formCollection變量,然後嘗試初始化它。奇怪的「對象引用未設置爲對象的實例」涉及xWinForms

每當我跑我得到停止在這條線的項目:

formCollection = new FormCollection(this.Window, Services, ref graphics); 

它給我的錯誤:

System.NullReferenceException was unhandled Message="Object reference not set to an instance of an object."
Source="Microsoft.Xna.Framework" StackTrace: at Microsoft.Xna.Framework.Graphics.VertexShader..ctor(GraphicsDevice graphicsDevice, Byte[] shaderCode) at Microsoft.Xna.Framework.Graphics.SpriteBatch.ConstructPlatformData() at Microsoft.Xna.Framework.Graphics.SpriteBatch..ctor(GraphicsDevice graphicsDevice) at xWinFormsLib.FormCollection..ctor(GameWindow window, IServiceProvider services, GraphicsDeviceManager& graphics) at GameSolution.Game2.LoadContent() in C:\Users\Owner\Documents\School\Year 3\Winter\Soen 390\TeamWTF_3\SourceCode\GameSolution\GameSolution\Game2.cs:line 45 at Microsoft.Xna.Framework.Game.Initialize() at GameSolution.Game2.Initialize() in C:\Users\Owner\Documents\School\Year 3\Winter\Soen 390\TeamWTF_3\SourceCode\GameSolution\GameSolution\Game2.cs:line 37 at Microsoft.Xna.Framework.Game.Run() at GameSolution.Program.Main(String[] args) in C:\Users\Owner\Documents\School\Year 3\Winter\Soen 390\TeamWTF_3\SourceCode\GameSolution\GameSolution\Program.cs:line 14 InnerException:

在一個項目中,我下載了用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); 
    } 
} 

任何幫助將不勝感激._。

回答

0

我應該強調我之前沒有使用過這個庫。然而,看着堆棧跟蹤,拋出異常的方法需要一個GraphicsDevice對象。我猜這個對象來自你的「圖形」對象的GraphicDevice屬性。在將它傳遞給FormCollection構造函數之前,請檢查該屬性是否包含您期望的內容。這可能有助於指引您朝着正確的方向發展。

1

我終於弄清楚發生了什麼...... 似乎我需要某種配置文件。 圖書館似乎是爲XNA 3.0,而我正在使用3.1 配置文件似乎做了兩種之間的某種映射。一旦我添加文件,它就解決了這個問題。但我仍然不完全確定。

相關問題