iDevGames Forums
CGContextFlush: invalid context with awt.Toolkit and awt.Graphics - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: CGContextFlush: invalid context with awt.Toolkit and awt.Graphics (/thread-3258.html)



CGContextFlush: invalid context with awt.Toolkit and awt.Graphics - Tools10 - Jun 6, 2007 02:02 PM

Anyone have any idea whatsoever what this is all about.
This is more or less the graphic part of the program

I'm using
Code:
Image i = Toolkit.getDefaultToolkit().createImage(AbsoluteImagePath);
to load the image and
Code:
getBufferStrategy().getDrawGraphics().drawImage(i, 100, 100, this);
getBufferStrategy().show();
to draw it in a subclass of java.awt.Frame.
The image is a 40x40 png created with Pixen 3.0.

The strange thing is that the first time I attempt to draw the image I will always get a "CGContextFlush: invalid context" message in the console, however, if I use getBufferStrategy().show() again it will paint the image without complaints, most of the times at least.
Sometimes it just refuses to draw anything at all.
Should point out that it's only the images loaded with Toolkit.createImage that behaves strangely, any graphic operation used on Images created with Component.createImage works fine and without any errors.

Anyone got any idea of what this is all about?
Thankful for any suggestions or input.

Here is a working code if anyone feel like testing what happens.
Code:
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.io.File;

public class LekMedToolkitImage extends Frame {
/**Loads and display a Image file.
@args filename the filename of the image file(with extension).*/
    public LekMedToolkitImage(String filename) {
        super();
        setSize(400, 300);
        setVisible(true);
        createBufferStrategy(2);
        File f = new File(filename);
        Image i = Toolkit.getDefaultToolkit().createImage(f.getAbsolutePath());
        while(true) {
            try {
                Thread.sleep(100);
            } catch(InterruptedException e) {}
            getBufferStrategy().getDrawGraphics().drawImage(i, 100, 100, this);
            getBufferStrategy().show();
        }
    }
    
    public static void main(String[] args) {
        new LekMedToolkitImage(args[0]);
    }
}

Not a pice of art but it should get the work done, the loop will repaint the image.


CGContextFlush: invalid context with awt.Toolkit and awt.Graphics - Tools10 - Jun 10, 2007 04:07 PM

Tried to draw all Images to a off-screen Image instead of directly to the frame.
Works fine, if anyone got a clue why please tell because I really can't explain this and I'm unable to find a reason in the documentation.