CGContextFlush: invalid context with awt.Toolkit and awt.Graphics

Posts: 3
Joined: 2008.04
Post: #1
Anyone have any idea whatsoever what this is all about.
This is more or less the graphic part of the program

I'm using
Image i = Toolkit.getDefaultToolkit().createImage(AbsoluteImagePath);
to load the image and
getBufferStrategy().getDrawGraphics().drawImage(i, 100, 100, this);
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.
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;

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) {
        setSize(400, 300);
        File f = new File(filename);
        Image i = Toolkit.getDefaultToolkit().createImage(f.getAbsolutePath());
        while(true) {
            try {
            } catch(InterruptedException e) {}
            getBufferStrategy().getDrawGraphics().drawImage(i, 100, 100, this);
    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.
Quote this message in a reply
Posts: 3
Joined: 2008.04
Post: #2
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.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  float FBO on iPhone (invalid operation error) Fenris 11 17,112 Jan 17, 2013 05:40 AM
Last Post: Fenris
  Bitmap font toolkit Najdorf 9 11,592 Nov 11, 2008 05:43 PM
Last Post: Najdorf
  Full screen context doesn't remain the current context Malarkey 3 5,532 Feb 1, 2007 05:27 PM
Last Post: OneSadCookie
  flushing a graphics context in SDL. dave05 1 4,287 Jun 9, 2005 01:36 PM
Last Post: sealfin
  A toolkit for OpenGL whogben 7 6,500 Aug 3, 2003 10:16 AM
Last Post: Feanor