GDI+ error

1
Chris Smith
1/19/2022 3:22 AM

Hi Wout,

The latest few versions of CadLib seem to be a bit more susceptible to "A generic error occurred in GDI+".

This seems to happen when some particular graphic is massively bigger or smaller than the view extent.

Using the attached DWG / code, you can see that we're rendering a very small extent but there are some very large graphics in the drawing.

This (mostly) worked fine in 4.0.38.86 but fails in 4.0.39.X. I say mostly because we definitely have still found cases where very very small graphics rendered in a very large extent still caused issues on that older version.

Code (assuming linqpad):

C# Code:
void Main()
{
    DxfModel dxf = DwgReader.Read(@"C:\temp\gdi.dwg");

    var width = 1000;
    var height = 1000;

    GraphicsConfig config = new GraphicsConfig
    {
        BackColor = ArgbColors.Black,
        CorrectColorForBackgroundColor = true,
        DisplayLineTypeElementShapes = true,
        DrawImageFrame = false,
        TryDrawingTextAsText = true,
        DisplayLineWeight = true,
        ApplyLineType = true
    };

    var gdiGraphics3D = new GDIGraphics3D(config);
    gdiGraphics3D.CreateDrawables(dxf);

    var bounds = new Bounds3D {
        Corner1 = new Point3D(-0.0014, -0.0009, 0),
        Corner2 = new Point3D(0.0054, 0.0023, 0)
    };

    var transform = DxfUtil.GetScaleTransform(
                        bounds.Corner1,
                        bounds.Corner2,
                        bounds.Center,
                        new Point3D(0d, height, 0d),
                        new Point3D(width, 0d, 0d),
                        new Point3D(width / 2, height / 2, 0d)
                    );

    var img = ImageExporter.CreateBitmap(gdiGraphics3D, transform, width, height);
    img.Dump();
}

Chris Smith
1/26/2022 10:15 PM

Hi Wout &c,

Just wondering if there's anything that can be done about this?

I assume the "CreateDrawables" call in the gdiGraphics3D is creating a bunch of segmented lines, is there a way we can filter those before calling CreateBitmap?

Perhaps we can be looking for things that won't convert well to Float or something...

Cheers,
Chris

1