簡體   English   中英

XNA 4.0 應用程序在遇到方法時突然關閉而不拋出任何異常

[英]XNA 4.0 app closes suddenly when it hits a method without throwing any exceptions

正如標題所說,我有一個 XNA 應用程序在遇到應用程序時突然關閉,但沒有顯示任何錯誤,所以我什至不知道如何開始調試它。 代碼非常簡單——我只是在玩 XNA 並嘗試渲染一個簡單的三角形——所以我無法想象它為什么會停止。 正在運行的代碼是

    VertexPositionColor[] vertices;

    public Terrain()
    {
        vertices = new VertexPositionColor[3];
        vertices[0].Position = new Vector3(-0.5f, -0.5f, 0f);
        vertices[0].Color = Color.Red;
        vertices[1].Position = new Vector3(0, 0.5f, 0f);
        vertices[1].Color = Color.Green;
        vertices[2].Position = new Vector3(0.5f, -0.5f, 0f);
        vertices[2].Color = Color.Yellow;
    }

    public void Draw(GameTime gameTime)
    {
        ScreenManager.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(
            PrimitiveType.TriangleList,
            vertices,
            0,
            1,
            VertexPositionColor.VertexDeclaration);
    }

是 Draw() function 搞砸了。 當我刪除 DrawUserPrimitives 行時,它運行良好(雖然什么都不顯示......)

我將假設“ScreenManager”是繼承“DrawableGameComponent”的 class 並且您正在從那里訪問圖形設備? 確保在您的游戲 class 的構造函數中的某處您正在初始化 GraphicsDeviceManager(this)。

我認為你的 ScreenManager 正在靜態抓取的“GraphicsDevice”可能沒有正確初始化。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM