I am currently writing a Fractal Explorer program, and I am having a very strange problem: I draw a fractal on a BufferedImage and I get random black areas in this image. Screenshots: http://imgur.com/a/WalM7
The image is multi-threaded: the large image is divided into four (since I have a quad-core processor) sub-images, which are calculated individually. Black areas appear at the beginning of each of the sub-images. They are always rectangular, not necessarily following the order in which the pixels are calculated (from left to right, but the area does not always extend to the far side of the sub-image).
I checked that immediately after drawing the pixel (with Graphics.drawLine), BufferedImage.getRGB returns the correct color for the pixel, but after the calculation is completed, it can return black instead, since the pixel is drawn on the screen.
The problem seems to disappear if I turn off multi-threaded computing (assigning only one core javaw.exe via task manager), but I really don't want to give up multi-core computing. Has anyone else run into this problem (I didn't find anything via Google and stackoverflow) and do you know how to fix this?
The call to Graphics.drawLine is synchronized on the Graphics object; if I additionally synchronized it with BufferedImage, nothing will change.
If you want to see the error yourself, you can download the program http://code.lucaswerkmeister.de/jfractalizer/ . It is also available on GitHub (https://github.com/lucaswerkmeister/JFractalizer), but I just recently switched to GitHub, and in the first GitHub this problem is already obvious.
source share