Skip to content

WebGL context lost.#3133

Merged
kripken merged 1 commit intoemscripten-core:incomingfrom
juj:webgl_context_lost
Jan 23, 2015
Merged

WebGL context lost.#3133
kripken merged 1 commit intoemscripten-core:incomingfrom
juj:webgl_context_lost

Conversation

@juj
Copy link
Collaborator

@juj juj commented Jan 16, 2015

Define behavior when attempting glGen* when the WebGL context is lost. In that case, issue GL_INVALID_OPERATION, generate resources with ID 0, and print an error if GL_ASSERTIONS is enabled.

…. In that case, issue GL_INVALID_OPERATION, generate resources with ID 0, and print an error if GL_ASSERTIONS is enabled.
@juj juj added the GL label Jan 16, 2015
@kripken
Copy link
Member

kripken commented Jan 16, 2015

Why the focus on glGen* methods? Shouldn't basically every command fail if the context was lost?

@juj
Copy link
Collaborator Author

juj commented Jan 16, 2015

This is to avoid a crash in those functions, when accessing a property of null later in those functions. The commands will naturally fail, but will/should not crash execution to a JS exception.

@kripken
Copy link
Member

kripken commented Jan 16, 2015

Still, why focus on those? Surely we would crash in many other GL methods, if the context is gone? (when using those objects, not just when creating them?)

@juj
Copy link
Collaborator Author

juj commented Jan 22, 2015

Yeah, then we should fix the other GL methods as well so that they don't crash either. I don't know which other methods we have that currently have this issue, do you have some specific in mind?

Note that not having a context is not the same as having a context that is lost. In other words, GLctx being not initialized is a case where by the spec GL is allowed to crash, but when the context that one has initialized goes into a lost state, calling any of the GL functions shall not crash, but instead they shall behave as no-ops that are ignored.

@kripken
Copy link
Member

kripken commented Jan 22, 2015

If this is an issue we need to fix, I hope we can find a better way. For example, we could automatically add to all GL calls a prelude

  if (!checkCtxLost()) return setError();

I guess the question is, should we report an error here. Or, we can listen for context loss, so we could throw a JS error in that case, which seems just as good - the application is going to fail anyhow?

@juj
Copy link
Collaborator Author

juj commented Jan 23, 2015

We don't want to throw a JS error if the user calls a GL function when the context is lost. Also, we don't need to raise a GL error on behalf of WebGL for any entry points that lead to calling to a WebGL function, since it is WebGL's responsibility already to handle the GL error correctly in that case. The existing GL functions should already behave fine like expected, just these resource creation functions in this PR had a bad pattern where they could fail, since they accessed a member of null. Applications don't fail when a GL context is lost, but that's a normal app lifecycle event where the application just cannot render until the GPU becomes available again. This occurs e.g. on Firefox OS every time the user presses the home screen button to switch between applications.

@kripken
Copy link
Member

kripken commented Jan 23, 2015

Ok, I didn't understand the background here, now I think I see.

kripken added a commit that referenced this pull request Jan 23, 2015
@kripken kripken merged commit 5badff0 into emscripten-core:incoming Jan 23, 2015
@juj
Copy link
Collaborator Author

juj commented Jan 23, 2015

Sorry, my bad for not explaining the rationale better in the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments