sharpdx / SharpDX

SharpDX GitHub Repository
http://sharpdx.org
MIT License
1.69k stars 641 forks source link

DeviceContextRenderTarget.EndDraw [D2DERR_WRONG_STATE/WrongState] #1000

Open SharinganShuriken opened 6 years ago

SharinganShuriken commented 6 years ago

Hello,

i tried to render a simple text on my form, but get's everytime an exception, that i set a wrong state by EndDraw :(

Code:

`
Factory1 factory = new Factory1();

        Device d3d11Device = new Device(factory.GetAdapter(0), DeviceCreationFlags.SingleThreaded | DeviceCreationFlags.BgraSupport);

        SwapChainDescription swapChainDescription = new SwapChainDescription();
        swapChainDescription.SampleDescription = new SampleDescription(1, 0);
        swapChainDescription.BufferCount = 1;
        swapChainDescription.OutputHandle = this.Handle;
        swapChainDescription.IsWindowed = true;
        swapChainDescription.Usage = Usage.RenderTargetOutput;
        swapChainDescription.ModeDescription = new ModeDescription(this.Width, this.Height, new Rational(75, 1), Format.B8G8R8A8_UNorm);

        SwapChain swapChain = new SwapChain(factory, d3d11Device, swapChainDescription);

        DeviceContextRenderTarget d2dDevice = new DeviceContextRenderTarget((new SharpDX.Direct2D1.Factory(SharpDX.Direct2D1.FactoryType.SingleThreaded)),
            new RenderTargetProperties(new PixelFormat(swapChain.Description.ModeDescription.Format, SharpDX.Direct2D1.AlphaMode.Ignore)));

        TextFormat format = new TextFormat(new SharpDX.DirectWrite.Factory(), "Arial", 1.0f);

        Surface backBuffer = swapChain.GetBackBuffer<Surface>(0);

        Graphics g = Graphics.FromHwnd(this.Handle);

        RenderTarget renderTarget = new RenderTarget(d2dDevice.Factory,
            backBuffer, new RenderTargetProperties(RenderTargetType.Hardware,
                new PixelFormat(swapChain.Description.ModeDescription.Format, SharpDX.Direct2D1.AlphaMode.Ignore), g.DpiX, g.DpiY, RenderTargetUsage.None, FeatureLevel.Level_10));

        SolidColorBrush brush = new SolidColorBrush(renderTarget, Color4.Black);

        d2dDevice.BeginDraw();
        d2dDevice.Clear(Color4.Black);
        d2dDevice.DrawText("Hello World", format, new SharpDX.RectangleF(0, 0, this.Width, this.Height), brush);
        d2dDevice.EndDraw();
        swapChain.Present(0, SharpDX.DXGI.PresentFlags.None);`

And if i Set the RenderTarget (I get an Invalid Arguments exception):

d2dDevice.BindDeviceContext(renderTarget.NativePointer, new SharpDX.Mathematics.Interop.RawRectangle(0, 0, this.Width, this.Height));

Can anyone help me?