Skip to content

Fix blank screen issue [#18]#26

Merged
ByteHamster merged 2 commits intoFlowit-Game:masterfrom
ywnico:blank-screen
Oct 29, 2022
Merged

Fix blank screen issue [#18]#26
ByteHamster merged 2 commits intoFlowit-Game:masterfrom
ywnico:blank-screen

Conversation

@ywnico
Copy link
Copy Markdown
Contributor

@ywnico ywnico commented Oct 24, 2022

Fix #18, in which switching apps or turning the screen off and on results in a blank screen.

When Flowit launches, onSurfaceChanged is called once. But when it resumes, onSurfaceChanged is called twice. The loaded matrix previously was not reset between calls, meaning that the second onSurfaceChanged would mess up all the coordinates. Adding gl.glLoadIdentity() in onSurfaceChanged fixes the issue.

On my phone, if I unlock using pin instead of fingerprint sensor, the initial dimensions of the created surface change. Therefore, to fix the graphics appearing in a slightly incorrect position, another gl.glLoadIdentity() in onSurfaceCreated is applied. (This one I don't really understand, so I'm not sure if there's a better fix, but it seems to work in my testing).

I think these two changes resolve the blank screen problem, but I'm not an expert on OpenGL and there may be some other edge cases that it doesn't address.

@ywnico
Copy link
Copy Markdown
Contributor Author

ywnico commented Oct 25, 2022

Actually, there is some vertical stretching of the graphics sometimes when I lock screen and unlock. I will investigate a bit more.

@ywnico
Copy link
Copy Markdown
Contributor Author

ywnico commented Oct 26, 2022

Although adding gl.glLoadIdentity() on the projection matrix in onSurfaceChanged solves the blank screen issue, it uncovers a second bug that I have not been able to solve.

If I change apps or lock and unlock the screen with the fingerprint reader (I'm on Galaxy S9 with Lineage 18.1 [Android 11]), there is no problem, and the app works as expected. But if I lock and unlock using pin code instead of fingerprint, then the interface sometimes becomes stretched vertically.

Normal Stretched

From debugging, I have determined that the available screen size on my phone (screen size minus the bottom navigation bar) is 1440 x 2792. These are the dimensions that are normally passed to onSurfaceChanged (which is always called twice on resume). However, in the case that I unlock the phone with the pin, the first onSurfaceChanged call is given dimensions of 1440 x 2960 (the size of my screen without the soft navigation bar) and the second call has the expected 1440 x 2792. Thus, it seems that perhaps the game is stretching a rendered 1440 x 2792 screen to 1440 x 2960, and placing it above the navigation bar, leading to the stretching and clipping effect.

What's strange is that even though unlocking with pin always first calls onSurfaceChanged with 1440 x 2960 and then with 1440 x 2792, the graphics are stretched only sometimes (approx 10%-20% of the times I lock and unlock). I have not been able to find a deterministic source; I just unlock and relock many times (without interacting with the app during that time) and eventually the bug will show up.

I thought maybe the GLSurfaceView itself was stretched, but it always reports its size [from glSurfaceView.getWidth(), glSurfaceView.getHeight() or glSurfaceView.getMeasuredWidth(), glSurfaceView.getMeasuredHeight()] normally as 1440 x 2792 and the reported position from glSurfaceView.getX() and glSurfaceView.getY() does not change.

So, I'm not sure if this is a bug related to OpenGL or related to the GLSurfaceView and layout (e.g., how fullscreen is set).

I will keep trying to figure it out, but I wanted to document the situation. Sorry for submitting the PR prematurely.

Copy link
Copy Markdown
Member

@ByteHamster ByteHamster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find, thanks a lot! I always assumed this was a problem with texture loading, not with the camera matrix. Nice! Even if it might sometimes stretch on some devices (not on mine), I'm sure it will already help a lot of users.

gl.glGenTextures(textures.length, textures, 0);
loadTexture(gl, 0, textureDrawables[currentColorschemeIndex]);

gl.glLoadIdentity();
Copy link
Copy Markdown
Member

@ByteHamster ByteHamster Oct 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the other one be enough? That's the only place where the view matrix is modified.

Edit: Ah, right, sorry. You already commented about that in the original post. And you are sure that this fixes something? Weird...

Copy link
Copy Markdown
Contributor Author

@ywnico ywnico Oct 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, you are correct. I had mistakenly thought it was relevant, but it was not. I think my OpenGL skills are at a kind of embarrassing level :)

I really don't know why this stretching is sometimes happening, but it does seem at least like less of a bug than the blank screen....

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it does seem at least like less of a bug than the blank screen....

Yeah, definitely. And the fix is so simple and clean, good find!

@ByteHamster ByteHamster merged commit aee804c into Flowit-Game:master Oct 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Switch to other app and switch back, get a blank screen

2 participants