Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid OpenGL: crazy aspect ratio after sleep
    text
    copied!<p>If I hit the power button on my android phone (or wait for it to time out) and the phone goes to sleep, after waking back up, the screen aspect ratio is all out of wack.</p> <p>Screenshots: </p> <p>broken</p> <p><img src="https://i.stack.imgur.com/zXg0F.png" alt="http://i.imgur.com/4C6ID.png"></p> <p>correct</p> <p><img src="https://i.stack.imgur.com/vJtOw.png" alt="http://i.imgur.com/CNAV0.png"></p> <p>in GameActivity.onCreate()</p> <pre><code> // Grab display info DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); ACTUAL_SCREEN_WIDTH = (int) dm.widthPixels; ACTUAL_SCREEN_HEIGHT = (int) dm.heightPixels; ACTUAL_DENSITY = dm.density; double scale = ((double) MainMenuActivity.resolutionScale / 100.0); SCREEN_WIDTH = (int) (ACTUAL_SCREEN_WIDTH * scale); SCREEN_HEIGHT = (int) (ACTUAL_SCREEN_HEIGHT * scale); DENSITY = ACTUAL_DENSITY * scale; // Setup graphics requestWindowFeature(Window.FEATURE_NO_TITLE); surface_view = new GLSurfaceView(this); if (SCREEN_WIDTH != ACTUAL_SCREEN_WIDTH || SCREEN_HEIGHT != ACTUAL_SCREEN_HEIGHT) surface_view.getSurfaceHolder().setFixedSize(SCREEN_WIDTH, SCREEN_HEIGHT); </code></pre> <p>I am reloading everything correctly in GLSurfaceView (i.e. hitting home and going back to the game reloads the textures, etc).</p> <p>I've printed out the orientation in onWindowFocusChanged, and it is landscape (as expected).</p> <p>The problem does not appear if I do not use setFixedSize (i.e. if resolutionScale is 100). Also, the problem disappears if another window appears in front of the game (like the preferences window) and then you return the game.</p> <p>Thanks in advance. I've been trying random things for about an hour since research dried up.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload