I think you should cache the value of `Display.isActive()` in a local variable here. The behavior might get weird if the status changes as this code is executing.