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

Nibbie
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
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.
Quote this message in a reply
Nibbie
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 8,126 Jan 17, 2013 05:40 AM
Last Post: Fenris
  Bitmap font toolkit Najdorf 9 6,865 Nov 11, 2008 05:43 PM
Last Post: Najdorf
  Full screen context doesn't remain the current context Malarkey 3 3,503 Feb 1, 2007 05:27 PM
Last Post: OneSadCookie
  flushing a graphics context in SDL. dave05 1 3,004 Jun 9, 2005 01:36 PM
Last Post: sealfin
  A toolkit for OpenGL whogben 7 3,959 Aug 3, 2003 10:16 AM
Last Post: Feanor