Skip to content
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

emscripten_set_orientationchange_callback does not work #21448

Closed
cwoffenden opened this issue Feb 28, 2024 · 1 comment
Closed

emscripten_set_orientationchange_callback does not work #21448

cwoffenden opened this issue Feb 28, 2024 · 1 comment

Comments

@cwoffenden
Copy link
Contributor

cwoffenden commented Feb 28, 2024

Tested with the latest main (6105e76) and 3.1.55 Emscripten. Adding an orientation change callback is either unsupported (iOS/Safari) or silently fails (Android/Chrome), but manually running the JS calls does work. Here's a minimal test:

#include <stdio.h>

#include <emscripten/em_js.h>
#include <emscripten/html5.h>

EM_JS(void, manually_add, (), {
    screen.orientation.addEventListener("change",
        function(e) {
            Module.print("Orientation (JS) changed: type: " + e.target.type + ", angle: " + e.target.angle);
        }
    );
});

EM_BOOL orientation(int type, const EmscriptenOrientationChangeEvent* e, void* data) {
    printf("Orientation (C) changed: type:%d, angle: %d\n", e->orientationIndex, e->orientationAngle);
    return EM_TRUE;
}

int main() {
    // add via Emscripten's HTML5 call
    EMSCRIPTEN_RESULT res = emscripten_set_orientationchange_callback(NULL, EM_FALSE, orientation);
    if (res ==  EMSCRIPTEN_RESULT_SUCCESS) {
        printf("Orientation callback supported and added\n");
    } else {
        printf("Unable to add orientation callback\n");
    }

    // add directly via JavaScript
    manually_add();
}

Build with: emcc -O0 -g3 -s ASSERTIONS=2 -o index.html test.c. A pre-built version of the repro can be seen here:

https://wip.numfum.com/2024-02-28/emscripten/orientation-cb/index.html

Either test on a tablet on in a browser's dev tools with the device toolbar enabled (e.g. Apple + Shift + M in Chrome). Rotate the device or change the dev tool rotation. Note that emscripten_set_orientationchange_callback() either fails to add or simply does nothing, but the JS screen orientation listener works on iOS, Android and desktop.

This is different from the ASSERTION issue reported in #21447.

@cwoffenden
Copy link
Contributor Author

A fix was added as part of #21428.

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

No branches or pull requests

1 participant