C# 类型为';的未处理异常;系统异常';发生在MonoGame.Framework.dll中
我目前正在尝试使用MonoGame创建一个简单的游戏 我目前面临的问题是,有时(有一半的时间)我的代码运行没有问题。但有时它会给我一个例外: MonoGame.Framework.dll中发生类型为“System.ArgumentNullException”的未处理异常 其他信息:值不能为空 所以我这里的问题是,既然这类问题并非一直都在发生,我们该如何处理它呢?C# 类型为';的未处理异常;系统异常';发生在MonoGame.Framework.dll中,c#,monogame,argumentnullexception,C#,Monogame,Argumentnullexception,我目前正在尝试使用MonoGame创建一个简单的游戏 我目前面临的问题是,有时(有一半的时间)我的代码运行没有问题。但有时它会给我一个例外: MonoGame.Framework.dll中发生类型为“System.ArgumentNullException”的未处理异常 其他信息:值不能为空 所以我这里的问题是,既然这类问题并非一直都在发生,我们该如何处理它呢? 我试过清洗我的溶液。但有时它仍然会在我清洗溶液后直接发生 堆栈跟踪在我的绘图()中;方法位于spriteBatch.Draw()行 p
我试过清洗我的溶液。但有时它仍然会在我清洗溶液后直接发生 堆栈跟踪在我的绘图()中;方法位于spriteBatch.Draw()行
public void Draw(SpriteBatch-SpriteBatch)
{
spriteBatch.Begin();
spriteBatch.Draw(InitialTexture,InitialPlatformPosition,InitialPlatformSprite,Color.White);
对于(int x=0;x您已经说过问题出在Draw方法中,所以更新方法可能与此无关。发布Draw方法和完整堆栈跟踪。通常,处理此类错误的方法是使用调试器,这意味着您有一个未初始化的变量,或者MonoGame中有一个bug。@craftworkgames非常感谢您谢谢你的解释。我似乎已经通过初始化TextureArray1和TextureArray2解决了这个问题。
public void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Begin();
spriteBatch.Draw(InitialTexture, InitialPlatformPosition, InitialPlatformSprite, Color.White);
for (int x = 0; x <= 4; x++)
{
spriteBatch.Draw(TextureArray1[x], PlatformPosition1 + new Vector2(platformWidth * x, 0), PlatformSprite, Color.White);
spriteBatch.Draw(TextureArray2[x], PlatformPosition2 + new Vector2(platformWidth * x, 0), PlatformSprite, Color.White);
}
spriteBatch.End();
}
public void Update(GameTime gameTime)
{
int speed = -(int)(gameTime.ElapsedGameTime.TotalSeconds * velocity);
InitialPlatformPosition += new Vector2(speed, 0);
PlatformPosition1 += new Vector2(speed, 0);
PlatformPosition2 += new Vector2(speed, 0);
// Create First Array of Random Texture
if (InitialPlatformPosition.X < -datum1)
{
datum1X++;
datum1 = datum1X * 1920;
for (int x = 0; x <= 4; x++)
{
random.Next(2);
if (random.Next(2) == 0)
PlatformChoice1 = Texture;
else if (random.Next(2) == 1)
PlatformChoice1 = TextureFlipped;
// insert random platform into an array of 10 Texture
TextureArray1[x] = PlatformChoice1;
}
if (datum1X != 1)
{
PlatformPosition1 += new Vector2(1920, 0);
}
}
// Create Second Array of Random Texture
if (InitialPlatformPosition.X < datum2)
{
datum2X++;
datum2 = -(1920 - datum2);
if (datum2X == 1 || datum2X >= 3)
{
for (int x = 0; x <= 4; x++)
{
random.Next(2);
if (random.Next(2) == 0)
PlatformChoice2 = Texture;
else if (random.Next(2) == 1)
PlatformChoice2 = TextureFlipped;
// insert random platform into an array of 10 Texture
TextureArray2[x] = PlatformChoice2;
}
}
if (datum2X >= 3)
{
PlatformPosition2 += new Vector2(1920, 0);
}
}
}