“外部组件已引发异常。”调用WicRenderTarget

问题描述:

代码时异常被称为:“外部组件已引发异常。”调用WicRenderTarget

try 
{ 
    renderBitmap = new WicRenderTarget(DXManager.Factory, host.bmp, new RenderTargetProperties()); 
} 
catch (Exception ex) 
{ 
    // Exists entirely so that we can set a break point to catch this on the Exception. 
    throw ex; 
} 

host.bmp是SharpDX.WIC.Bitmap。我们偶尔会得到上述“外部组件已经抛出异常。”用“-2147467259”(它映射到0x80004005的或“未指定错误”)的错误代码异常和以下堆栈跟踪:

at SharpDX.Direct2D1.Factory.CreateWicBitmapRenderTarget(Bitmap target, RenderTargetProperties& renderTargetProperties, RenderTarget renderTarget) 
    at SharpDX.Direct2D1.WicRenderTarget..ctor(Factory factory, Bitmap wicBitmap, RenderTargetProperties renderTargetProperties) 
    at MyCompany.Framework.DirectX.DXRenderableImage.Surface..ctor(DXRenderableImage Target, PointF NewOrigin, Color BackgroundColor) in Source ....\\Framework\\DirectX\\DXImageSurface.cs:line 150 

用于DXRenderableImage.Surface构造的代码是在顶部提到的代码这个问题基本上只是调用WicRenderTarget构造函数。

据我所知,工厂是好的。当我们正在快速连续处理相当复杂的页面时,会发生此异常,并生成用于保存页面的预览缩略图。我们的线程保存逻辑应该一次只能调用一个,所以这应该被门控。这可能与难以达到渲染锁定(我们已经在类似情况下看到了不同的例外情况)。

我只是对如何去调试这个问题感到困惑。该例外没有任何支持信息,否则一切似乎都是有序的。有没有人有我的答案,或者找出答案的好方法?

+0

这个异常是否有内部异常?内部异常有什么信息? –

+0

@ChetanRanpariya:没有内在的例外。 –

+1

与你的问题无关,但重新抛出异常,你不应该使用“扔前”这会吃掉你的堆栈跟踪。最好使用“throw”来保留你的堆栈跟踪。 – Gurpreet

当你使用它们的时候,你有没有试过处理你的对象?这可能是内存泄漏。您可以在它

finally 
{ 
    renderBitmap.Dispose(); 
} 

一个finally块添加到您的try/catch和调用Dispose()或使用使用

using (renderBitmap = new WicRenderTarget(DXManager.Factory, host.bmp, new RenderTargetProperties())) 
{ 
    // do the stuff you want with the render-bitmap 
} 
+0

:)一个小问题... renderBitmap需要通过构造函数持久化。但是,是的,我们在课程处理完毕时会调用Dispose。 –

我重新张贴这作为一个答案,而不是评论。

首先 0x80004005的错误通常表示拒绝访问/锁定的情况。你认为你正在加载的图像(host.bmp)可能在两个线程之间被锁定?你有没有检查你的方法是否线程安全?你应该在读入内存后释放所有加载的图像。

其次 你可能不是因为你使用的是“扔恩”重新抛出异常,这将吃掉你的堆栈跟踪获取内部异常。最好使用“throw”来保留你的堆栈跟踪。

+0

你的问题是更好的答案,但它仍然不能解决我如何解决这个问题。 –

+0

我能做些什么来帮助的是审查一些代码,看看我能否找到重构和尝试的东西。我不知道你是否可以通过git hub或其他东西共享一些代码。 – Gurpreet