1

I am drawing a complex path to render a 3D image from scratch. It is the task and use of 3D engines is not allowed.

I am using:

GraphicsContext gc = getGraphicsContext2D();
gc.clearRect(x, y, w, h);
gc.appendSVGPath(svg);
gc.stroke();

svg is a very long string that contains svg graphic.

What I have noticed is that the value of gc.path.pointTypes.length keeps increasing by > 400k each time graphics are rendered and that slows down simulation with each loop.

How can I clear the path of GraphicsContext?

ps: It is package-private, no access.

1 Answer 1

1

Call beginPath() before appendSVGPath().

https://docs.oracle.com/javase/8/javafx/api/javafx/scene/canvas/GraphicsContext.html#beginPath--

1
  • I have really missed that one out, reading the docs. Thank You! Though beginPath() is not what you would expect. Commented Apr 12, 2017 at 21:42

Not the answer you're looking for? Browse other questions tagged or ask your own question.