0

I am using SharpenLines3d in my projects to draw lines to connect objects in my Viewport3D. Problem is, when I'm adding points to ScreenSpaceLined3D, the program crashes, like this:

enter image description here

It crashes not in these lines when I'm adding points to ScreenSpaceLines3D, so it's something inside the library, I guess.

Here is my code:

for (int i = 0; i < MAX + 1; i++)
{
    ...

    var bounds = this.points[i].Bounds;

    var x = bounds.X + (bounds.SizeX / 2);
    var y = bounds.Y + (bounds.SizeY / 2);
    var z = bounds.Z + (bounds.SizeZ / 2);

    coords[i] = new Point3D(x, y, z);

    for (int j = 0; j < i; j++)
    {
        lines[i, j] = new ScreenSpaceLines3D();
        lines[i, j].Color = Colors.Red;
        lines[i, j].Thickness = 6;

        lines[i, j].Points.Add(coords[i]);
        lines[i, j].Points.Add(coords[j]);
    }

}

I am sure that I am not passing null as argument to Add function (I tried to replace my Add line with this: lines[i, j].Points.Add(new Point3D(0, 0, 0));, and it still didn't work).

And I commented out all code that uses lines variable, so this variable is used only when a bunch of new ScreenSpaceLines3D is created. But my program crashes not on initializing.

When I comment out 2 strings of code where I'm adding points to lines, program starts working okay, but when I'm adding it again, result is as in screenshot.

How to deal with it?

UPD: Adding MainViewPort.Children.Add(lines[i, j]); after adding points made it work. It is getting more and more strage.

4

1 回答 1

1

Somehow adding MainViewPort.Children.Add(lines[i, j]); solved the problem. Without it, program crashes, but with it, everything works okay.

I don't know how this works but this is it.

于 2015-05-22T09:41:01.503 回答