jingwood / d2dlib

A .NET library for hardware-accelerated, high performance, immediate mode rendering via Direct2D.
MIT License
245 stars 43 forks source link

DrawPath and FillPath throw exception #98

Open MarkhusGenferei opened 1 year ago

MarkhusGenferei commented 1 year ago

Hi, This library is really great !

I am exploring geometries. In a form subclassing D2DForm, the code sample below throws a System.AccessViolationException : 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'

What am I doing wrong ? Thank you

protected override void OnRender(D2DGraphics g)
{
  g.Clear(D2DColor.FromGDIColor(this.BackColor));

  using (var rect = this.Device.CreateRectangleGeometry(new D2DRect(10, 10, 20, 20)))
  {
     g.DrawPath(rect, D2DColor.BlueViolet, 1, D2DDashStyle.Dash);
  }

  using (var circle = this.Device.CreateEllipseGeometry(new D2DPoint(100, 100), new D2DSize(50, 50)))
  {
     using (var pen = this.Device.CreatePen(D2DColor.BlueViolet, D2DDashStyle.Dash))
     {
      if (pen != null)
      {
          g.DrawPath(circle, pen, 2);
          g.FillPath(circle, D2DColor.DarkBlue);
      }
     }
  }
}
jingwood commented 1 year ago

Confirmed that is a bug from CreateRectangleGeometry, please wait for it get fix. Thanks for report!

MarkhusGenferei commented 1 year ago

Thank you ! It looks this also apply to ellipse geometries.