BufferStrategy.getDrawGraphics()  blocks AWTE

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.

What Java version you on?

Kev

PC, 1.4.2_04
Mac, 1.4.2_05

Btw, apologies if this should be in the Java2D forum…

Cheers,

John

listener.frameRendering() from what I remember was just a callback to the application to render whatever it wanted to render. The application was responsible for performing a sleep of some sort.

So, if you’ve modified it not to sleep in frameRendering() it’ll get in a tight loop preventing the AWT event thread running. If you remove the line all together there’s no way it’d sleep so same effect.

I am surprised however that when you tried adding the sleep() directly into that loop it didn’t resolve the issue. I guess the next question is how did you modify it, what did you add into frameRendering()?

Kev

You on OSX or winblows at the moment?

Kev

Same on both - have them side by side here, so I test everything on each.

Just in case, and because I’m in some doubt as to what GAGE is actually up to on OS X, I modifed your SystemTimer class to just use System.currentTimeMillis() - again, no change.

There must still be a change of mine in there causing this, but I’m failing to see it.

John