Ani
Ani

Reputation: 10896

Appcrash when mixing Direct2D and Direct3D (SlimDX)

In my Direct3D 10.1 application, I'm trying to mix D2D and D3D drawing code. While the drawing code works fine, the app invariably crashes (in module d3d11.dll, with code c0000005) after an indeterminate amount of time (minutes, not hours). I've posted the relevant sections of code below, please ask if you want to see any other bits and I can add them to this question.

DeviceCreationFlags

D3D10.DeviceCreationFlags deviceflags = D3D10.DeviceCreationFlags.BgraSupport; // Doesn't work without this flag

Device creation

SlimDX.Direct3D10_1.Device1.CreateWithSwapChain( null, D3D10.DriverType.Hardware, deviceflags, SlimDX.Direct3D10_1.FeatureLevel.Level_10_1, swapchaindesc, out device, out swapchain );

Direct2D initialization

        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);
        }

Drawing code

    private void Draw2D()
    {
        d2dRt.BeginDraw();

        // Drawing code here

        var hr = d2dRt.EndDraw();

        if (hr != SlimDX.Direct2D.ResultCode.Success)
            Console.WriteLine("EndDraw result: {0}", hr);
    }

Thanks in advance!

Upvotes: 0

Views: 384

Answers (0)

Related Questions