"Freezes" when focus lost

I figured I’d find something on here to counter this eventually so I ignored it till now. Whenever I change focus to something else and then back to the lwjgl app, the app becomes unresponsive. It appears to use 99% of my CPU. I thought perhaps the if (!Window.minimized()) stuff was meant to take care of this, and I also tried adding a sleep thread as an else to help take care of things, but to no avail… Any recommendations?

You are in complete control!
That means, that when you see that Window.isMinimized is true, you need to determine what you want to do when minimized (or out of focus). This typically means that you’d want to do something like this:

if (Window.isMinimized()) {
  try {
    Thread.sleep(250);
  } catch (InterruptedException inte) {
  }
  
  if(Window.isDirty()) {
    render(); // Render To Screen
    Window.paint();
  }
} else {
  mainLoop(); // Launch The Main Loop
  render(); // Render To Screen
  Window.paint(); // Swap Opengl Buffers
}

FWIW, this works fine here ::slight_smile:

I’ve changed my main loop to be very similar to your example, but I get the same results:


        while(!Keyboard.isKeyDown(Keyboard.KEY_ESCAPE) && !Window.isCloseRequested()) {
            if (Window.isMinimized()) {
              try {
                Thread.sleep(250);
              } catch (InterruptedException inte) {
                inte.printStackTrace();
              }

              if(Window.isDirty()) {
                render(); // Render To Screen
                Window.paint();
              }

            } else {
                processKeyboard();                                                // Check keyboard input
                render();                                                            // Render opengl scene
//                Window.update();                                                // Update window graphics
                Window.paint();                                                      // Swap Opengl Buffers
        }
    }

Please state your OS and LWJGL version. Also, how unresponsive are we talking? Does it show frames but fails to react to input or is it completely dead?

  • elias

I’ve tried this under all 3 of my PCs and a friend’s laptop.

OS: Win2000 Professional SP4
Card: ATI Radeon 9800XT (Also happens on GF2 MX, GF4 ti4600 and a mobile GF FX – that one under WinXP)
LWJGL: lwjgl-0.8-win32

By unresponsive, I mean if I alt-tab or click on another window and then try to switch back, the window will not come back to the fore-front. If I hide all the other windows and wait for a bit, I eventually see a black unresponsive window (the title bar repaints ok) that can not be clicked on, closed, repositioned, etc… In full screen mode, if I alt-tab out of my app, the resolution does not switch back to normal (I assume it should) and I can not alt-tab back to my app. In Task Manager it doesn’t claim to be using 99% of the CPU anymore, probably a product of adding in the sleep(250)… But, the app is still listed as “Not Responding”.

So in summary, dead.

Your call to Window.update() is commented out during normal rendering and simply missing from minimized state. You must always call Window.update() every tick, minimized or not, as that’s the call that processes operating system events.

Cas :slight_smile:

Ah, that fixed the problem and makes sense now that I know what that command does…

Perhaps I can help write an LWJGL FAQ with all the questions I’ve been asking… :smiley:

All documentation contribution gratefully received :slight_smile:

Cas :slight_smile: