【问题标题】:How can i find what cause a null exception ? I mean what line or where in the code the exception throw?我怎样才能找到导致空异常的原因?我的意思是异常抛出的代码中的哪一行或哪里?
【发布时间】:2015-01-30 23:54:23
【问题描述】:

我正在运行我的程序,一段时间后它正在运行它抛出这个异常:

我在我的程序中使用了directx,并且在我所做的表格顶部使用了direct3d:

using Microsoft.DirectX.Direct3D;
using Microsoft.DirectX;

我在我的程序中使用 Direct3D.Sprite 和 Device 以及 Texture PresentParameters 和 DisplayMode 都连接到 DirectX.Direct3D

在异常消息中它说的是关于 OnLostDevice() 和其他的东西。但它没有给出任何具体的行或代码中的问题所在。

有什么方法可以找出问题的原因吗?

System.NullReferenceException was unhandled
  HResult=-2147467261
  Message=Object reference not set to an instance of an object.
  Source=Microsoft.DirectX.Direct3DX
  StackTrace:
       at Microsoft.DirectX.Direct3D.Sprite.OnLostDevice()
       at Microsoft.DirectX.Direct3D.Sprite.OnParentLost(Object sender, EventArgs e)
       at System.EventHandler.Invoke(Object sender, EventArgs e)
       at Microsoft.DirectX.Direct3D.Device.raise_DeviceLost(Object i1, EventArgs i2)
       at Microsoft.DirectX.Direct3D.Device.Finalize()
  InnerException: 

【问题讨论】:

  • 我可以将整个项目上传到我的skydrive,因为问题的形式是大量代码,而且项目本身我无法将其上传到这里。也许如果有人尝试使用我的程序,他将能够找到并查看问题所在。

标签: c# .net winforms directx direct3d


【解决方案1】:

首先将项目的Configuration 放入Debug。目前你在Release!在您的屏幕截图中,您可以通过Continue 按钮看到它。之后你应该Debug你的项目。

当您在调试时,您可以在选中Debug/Exceptions/Common Language Runtime Exceptions 中的复选框时看到引发异常的确切行。

【讨论】:

  • mybirthname 好的,我按照你说的做了,现在它正在停止并抛出异常的空异常: if (rgbValuesWithClouds[p] != rgbValuesWithoutClouds[p]) say Index was outside the bounds of在我进行此更改之前,数组可能是它显示空异常的原因?
  • 我的意思是这可能是我直到现在才看到它的问题,直到更改为调试并做了复选框?
  • 我现在将解决这个异常我只是想知道之前的 null 是否可能来自这个异常?我的意思是,如果这个索引超出了数组的范围,那么之前的 null 可能是什么?
  • 是的,这就是问题所在,当异常发生时发布整个代码块。最好在您最初的问题中发布整个方法。问题是对于这个 p 在这个集合中没有这个索引的元素
  • 好的,我会或将为此例外提出一个新问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-02-08
  • 2012-11-06
  • 2011-06-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多