Hi Ken,
first of all, rendering to the same graphics context from
multiple thread is not a good idea. Java2D does not
guarantee thread safety, and doing so could
lead to unpredictable results (and even crashes due
to bugs in our code). So, please don't do that.
As to your question why it "works" - you just got
lucky and the paint on EDT executed while another
thread was in between the getDrawGraphics() and dispose().
After the dispose() all rendering operations to a
graphics context become no-ops, so by definition you
would only see something rendered the paint event
happened to be while the graphics was still valid.
Thank you,
Dmitri
Java2D Team
Ken Warner wrote:
According to the documentation on:
http://java.sun.com/javase/6/docs/api/java/awt/image/BufferStrategy.html
One is supposed to
do {
Graphics graphics = strategy.getDrawGraphics();
//render here
graphics.dispose();
} while (strategy.contentsRestored());
So I did that where I render:
do {
do {
bg = (Graphics2D)bs.getDrawGraphics();
mis.newPixels(pixels, cm, 0, thisW);
bg.drawImage(canvasImage, 0, 0, thisW, thisH, this);
drawAttribution();
bg.dispose();
} while (bs.contentsRestored());
bs.show();
} while (bs.contentsLost());
So I'm disposing of bg -- the BufferStrategy graphics after I render.
The question is -- how come I can still use the buffer graphics (bg)
at other times to draw stuff. My applet draws onto the BufferStrategy (bs)
in many other places at various times. And it works and all the while
I have dispose()'ed of the buffergraphics (bg) and the loop above is the
only
place I getDrawGraphics();
For example -- here's my paint() method -- no problem -- no drawGraphics.
public void paint(Graphics g)
{
//System.err.println("paint()");
bg.drawImage(canvasImage, 0, 0, thisW, thisH, this);
if(DRAWATT)
drawAttribution();
bs.show();
}
I don't understand that...
Ken
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".