在我的 Direct3D 10.1 应用程序中,我试图混合 D2D 和 D3D 绘图代码。c0000005
虽然绘图代码工作正常,但应用程序总是在一段不确定的时间(几分钟,而不是几小时)后崩溃(在模块 d3d11.dll 中,使用 code )。我已经在下面发布了相关的代码部分,请询问您是否想查看任何其他位,我可以将它们添加到这个问题中。
DeviceCreationFlags
D3D10.DeviceCreationFlags deviceflags = D3D10.DeviceCreationFlags.BgraSupport; // Doesn't work without this flag
设备创建
SlimDX.Direct3D10_1.Device1.CreateWithSwapChain( null, D3D10.DriverType.Hardware, deviceflags, SlimDX.Direct3D10_1.FeatureLevel.Level_10_1, swapchaindesc, out device, out swapchain );
Direct2D 初始化
d2dFactory = new SlimDX.Direct2D.Factory(FactoryType.SingleThreaded);
using (var backBuffer = SlimDX.Direct3D10.Resource.FromSwapChain<SlimDX.Direct3D10.Texture2D>(swapchain, 0))
{
d2dSurf = backBuffer.AsSurface();
System.Drawing.SizeF dpi = d2dFactory.DesktopDpi;
d2dRt = SlimDX.Direct2D.RenderTarget.FromDXGI(d2dFactory, d2dSurf,
new SlimDX.Direct2D.RenderTargetProperties()
{
Usage = SlimDX.Direct2D.RenderTargetUsage.None,
Type = SlimDX.Direct2D.RenderTargetType.Default,
PixelFormat = new SlimDX.Direct2D.PixelFormat(SlimDX.DXGI.Format.Unknown, SlimDX.Direct2D.AlphaMode.Premultiplied),
});
color = new SlimDX.Color4(Color.White);
brush = new SlimDX.Direct2D.SolidColorBrush(d2dRt, color);
}
绘图代码
private void Draw2D()
{
d2dRt.BeginDraw();
// Drawing code here
var hr = d2dRt.EndDraw();
if (hr != SlimDX.Direct2D.ResultCode.Success)
Console.WriteLine("EndDraw result: {0}", hr);
}
提前致谢!