rendering image doesn't work every time

Hi,
I’m having the following strange problem (sometimes it works sometimes not).
Every tile of my map is prerendered at the beginning of the game:


private void prerender(int iTile) {
     BufferedImage renderedTile = mGfxConfig.createCompatibleImage(Tile.WIDTH, Tile.HEIGHT, Transparency.BITMASK);
     Graphics2D g2D = renderedTile.createGraphics();
     g2D.drawImage((Image) mTileImages.get("plain"), 0, 0, null);
     //...
     mRenderedTiles.put(new Integer(iTile), renderedTile);
     g2D.dispose();
}

Ok. Here’s the method putTile which is called by the main render loop:


public void putTile(Graphics g, int x, int y, int iTile) {
     if(!mRenderedTiles.containsKey(new Integer(iTile)))
           prerender(iTile);
     g.drawImage((BufferedImage) mRenderedTiles.get(new Integer(iTile)), x, y, null);
}

Ok, now the problem is: sometimes it works but often it doesn’t. Sometimes mRenderedTiles contains just empty images with nothing painted on.
What could be the problem?

how are you loadng the tile images? (the ones stored in mTileImages)

with Toolkit.getDefaultToolkit().getImage(…);

and are you using a MediaTracker to ensure the image is fully loaded before you attempt to use it?

Sounds like you arn’t.

Either use MediaTracker, or the better solution, use javax.imageio.ImageIO.read().

Uhhuhuuuuu, that hurts. Thanks, man.