I was playing with kevglass’s space invaders code and managed to break it and can’t quite figure out how.
Here’s the method in question:
private void gameLoop() {
while (gameRunning) {
// Get hold of a graphics context for the accelerated
// surface and blank it out
g = strategy.getDrawGraphics();
// give the application a chance to do its thing
if (listener != null) {
listener.frameRendering();
}
// finally, we've completed drawing so clear up the graphics
// and flip the buffer over
g.dispose();
strategy.show();
}
}
And this line:
g = strategy.getDrawGraphics();
seems to block all AWTEvents from being dispatched. A little debugging shows that all listeners are still properly attached and that nothing is changed on the Component that I’m subclassing (including event masks and the like). It just doesn’t seem to be dispatching the events.
Commenting out each line in turn led me to blame this line.
The code called by
listener.frameRendering();
has no effect - it works if I use JOGL instead and the effect is still present if I comment out that line altogether.
So, perhaps a busy CPU? Adding Thread.sleep()s doesn’t change anything either.
Any hints, clues or tips much appreciated.