sharpdx / SharpDX

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

GdiInteropRenderTarget.GetDC() System.AccessViolationException #832

Closed KingSora closed 7 years ago

KingSora commented 7 years ago

Hello!

I'm getting a System.AccessViolationException if I try to call the GetDC() method from a GdiInteropRenderTarget object.

My code:

D3D10.Texture2D texture = new D3D10.Texture2D(d3d1Device, d3dTextureDescription);

DXGI.Surface textureSurface = texture.AsSurface();

D2D.RenderTarget renderTarget = new D2D.RenderTarget(d2dFactory, textureSurface, renderTargetProperties);

renderTarget = new D2D.BitmapRenderTarget(renderTarget, D2D.CompatibleRenderTargetOptions.GdiCompatible, renderTargetProperties.PixelFormat);

D2D.GdiInteropRenderTarget gdiTarget = new D2D.GdiInteropRenderTarget(renderTarget.NativePointer);

renderTarget.BeginDraw();
//...
gdiTarget.GetDC(D2D.DeviceContextInitializeMode.Copy); //System.AccessViolationException

Can anyone help me with this? I've the current version of SharpDX.

Best regards, Sora

xoofx commented 7 years ago

You can't create a D2D.GdiInteropRenderTarget gdiTarget = new D2D.GdiInteropRenderTarget(renderTarget.NativePointer);, you are not supposed to to use native COM pointer directly unless you know which object you are passing.

As specified on the msdn documentation, you need to QueryInterface<GdiInteropRenderTarget> on the renderTarget directly.

KingSora commented 7 years ago

Alright thanks! Its woring now :)