I'm getting some very nasty JAVA2D glitches after recent updates to Lion's Java JVM. Where you would expect smooth shape outlines, I'm getting variably jagged outlines. I've confirmed that these issues aren't present on 1.5 JVMs, or on any 1.6 JVM releases prior to Jan 2012 or so.
And here's the output I'm seeing on Lion. Same issue with either the 1.6.0_31 or 1.6.0_29 JVMs, and Processing 1.5.1 vs 2.0a5 doesn't make a difference either. This same code produces a perfect circle on earlier JVMs:
Any ideas? Looks like a JVM bug but I haven't been able to find a work-around.
This is a possibly related post from a few months ago:
Hi Calsign, thanks for responding and testing the code. However, I already played around with smoothing, and tried different theta incrementation values... I get the same errors even (albeit to a lesser degree). Again the code I posted draws fine on Java 1.5, even with theta += 0.1.
For example, here's a version of the test code which only draws on whole-number increments and never places a vertex on the same pixel location twice...
The glitch can be isolated to the stroke drawing routines... filled shapes still draw cleanly. For example, if set noStroke() and draw with a fill instead, the same code (even with the 0.1 theta increment) draws just fine. Here's the slightly modified code:
Thanks asimes, but this is just the simplest case required to reproduce the error — I'm running into the error in a more complicated context where there aren't clear work-arounds.
This is a core component of the drawing API's functionality that used to work and now seems to be badly broken. We shouldn't need a work-around for drawing lines.
I poked around a bit more and found that beginShape(POINTS); or beginShape(LINES); seems to help aesthetically, but it's still not actually drawing the correct thing. Also combining beginShape(LINES); with strokeCap(SQUARE); produces similarly broken results.
If you watch closely while it draws, it seems like whatever code is responsible for rotating the end of the stroke cap to the perpendicular of the line's path is acting inconsistently. These errors accumulate into the jagged stroke outline in the screenshot above.
I've created some test cases that seem to further suggest that the issue is with how the angle of a line's end cap is calculated.
Again here's an overview of how the same code (from the first post in this thread) looks under Java 1.5 vs. Java 1.6:
The bottom example is another batch of test code designed to show exactly how the line segments are drawing. If you look carefully you can see that the segment caps are getting drawn at slightly variable angles in Java 1.6, while Java 1.5 draws them consistently and correctly. The red lines show the correct angles from the circle formula. Here's a closer look:
Next I'll try to see if I can reproduce this using pure Java instead of the Processing API... but from poking around the source for Processing's JAVA2D renderer it doesn't look Processing is doing anything particularly strange... so I'm assuming this is a Java bug.
Looks like this is a problem with Java 1.6 on Windows as well.