-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Soft fullscreen removes <body> element so document.body.style causes null deref #49
Comments
Didn't see this before, but could this be useful? https://github.com/kripken/emscripten/blob/master/tests/test_glfw_fullscreen.c - not using glfwSetWindowMonitor added in #9 since emscripten doesn't have it (glfw 3.2+), but rather emscripten's fullscreen and a glfw window size callback |
Starting from test_glfw_fullscreen, writing a minimal example, am able to successfully toggle between fullscreen and "fullwindow" (emscripten soft fullscreen), whipped up a demo here: test_fullscreen_fullwindow_toggle (source) - press F11 to toggle. So there may be some error on my end causing this body tag problem.
In the working test_fullscreen_fullwindow_toggle example, using void on_key(GLFWwindow *window, int key, int scancode, int action, int mods) {
if (action && GLFW_PRESS && key == GLFW_KEY_F11) {
printf("glfwSetKeyCallback: F11 pressed\n");
// F11 toggles between fullscreen and fullwindow ("soft fullscreen") mode. The app starts
// in fullwindow, a solid gray page. When fullscreen is entered with F11, the entire
// screen should be solid gray. Returning to fullwindow with F11 should also show the same.
EmscriptenFullscreenChangeEvent fsce;
EMSCRIPTEN_RESULT ret = emscripten_get_fullscreen_status(&fsce);
if (!fsce.isFullscreen) {
emscripten_exit_soft_fullscreen();
// Enter fullscreen
EmscriptenFullscreenStrategy strategy = {
.scaleMode = EMSCRIPTEN_FULLSCREEN_SCALE_STRETCH,
.canvasResolutionScaleMode = EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_STDDEF,
.filteringMode = EMSCRIPTEN_FULLSCREEN_FILTERING_DEFAULT,
.canvasResizedCallback = on_canvassize_changed,
.canvasResizedCallbackUserData = NULL
};
EMSCRIPTEN_RESULT ret = emscripten_request_fullscreen_strategy(NULL, EM_TRUE, &strategy);
printf("emscripten_request_fullscreen_strategy = %d\n", ret);
//EM_ASM(Module.requestFullscreen(1, 1)) ret=1 is test_fullscreen_fullwindow_toggle had a bug: enter fullscreen with F11, then exit with Escape (instead of F11). This takes you back to "presentation mode", instead of fullwindow. update: fixed in satoshinm/emglfwbugs@235fc0c with test_fullscreen_fullwindow_toggle works well as a test, but in porting it into NetCraft, F11 toggle now works well, but a new problem arises: resizing the window to the size of the canvas, as the browser window changes, instead of leaving it fixed dimensions:
diff --git a/src/main.c b/src/main.c
index 6989eb8..be85f2e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -2419,6 +2419,24 @@ void on_mouse_button(GLFWwindow *window, int button, int action, int mods) {
}
}
+static int inFullscreen = 0;
+static int wasFullscreen = 0;
+void windowSizeCallback(GLFWwindow* window, int width, int height) {
+ int isInFullscreen = EM_ASM_INT_V(return !!(document.fullscreenElement || document.mozFullScreenElement || document.webkitFullscreenElement || document.msFullscreenElement));
+ if (isInFullscreen && !wasFullscreen) {
+ printf("Successfully transitioned to fullscreen mode!\n");
+ wasFullscreen = isInFullscreen;
+ }
+
+ if (wasFullscreen && !isInFullscreen) {
+ printf("Exited fullscreen. Test succeeded.\n");
+ wasFullscreen = isInFullscreen;
+ //emscripten_cancel_main_loop();
+ return;
+ }
+ printf("windowSizeCallback %d x %d\n", width, height);
+}
+
#ifdef __EMSCRIPTEN__
// Emscripten's "soft fullscreen" = maximizes the canvas in the browser client area, wanted to toggle soft/hard fullscreen
void maximize_canvas() {
@@ -2808,6 +2826,7 @@ int main(int argc, char **argv) {
#else // web pointer lock requires user action to activate, start off disabled
glfwSetInputMode(g->window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
#endif
+ glfwSetWindowSizeCallback(g->window, windowSizeCallback);
glfwSetKeyCallback(g->window, on_key);
glfwSetCharCallback(g->window, on_char);
glfwSetMouseButtonCallback(g->window, on_mouse_button); , but not windowed browser resize. For that, there is emscripten has emscripten_set_canvas_size(), so could check that on each iteration, if changes, then glfwSetWindowSize. continue in #52 |
Testing on Chrome, press F11 to enter fullscreen, F11 again to exit, then this exception is thrown:
Uncaught TypeError: Cannot read property 'style' of null
at HTMLDocument.restoreOldStyle (craft.js:9026)
because emscripten's soft fullscreen seems to remove all other elements in the html document including
<body>
, so document.body is null!Attempted in #48 to workaround this by doing my own "windowed full" mode, but it stretches the canvas undesirably, so using soft fullscreen in emscripten is desirable but this is probably a bug in its implementation (who removes body from html? bad idea?).
The text was updated successfully, but these errors were encountered: