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

MEMORY64: GLFW drop function passes incorrect filename values #23505

Closed
oitel opened this issue Jan 27, 2025 · 4 comments · Fixed by #23676
Closed

MEMORY64: GLFW drop function passes incorrect filename values #23505

oitel opened this issue Jan 27, 2025 · 4 comments · Fixed by #23676

Comments

@oitel
Copy link
Contributor

oitel commented Jan 27, 2025

The onDrop function in libglfw.js has two different issues in the wasm64 version:

  1. The drop callback's dyncall sets the filenames parameter to number, while on wasm64 it is BigInt.
  2. The filenames array allocates 4 bytes per element, while on wasm64 it is 8.

Example output for 5 input files (running on Firefox 134):

Uncaught TypeError: can't convert 97048 to BigInt
    onloadend http://localhost:8000/main.js:5605
    onloadend http://localhost:8000/main.js:5605
    save http://localhost:8000/main.js:5595
    onDrop http://localhost:8000/main.js:5621
    _glfwInit http://localhost:8000/main.js:6110
    makeWrapper___PP http://localhost:8000/main.js:6257
    createExportWrapper http://localhost:8000/main.js:617
    callMain http://localhost:8000/main.js:6594
    doRun http://localhost:8000/main.js:6646
    run http://localhost:8000/main.js:6655
    setTimeout handler*run http://localhost:8000/main.js:6653
    removeRunDependency http://localhost:8000/main.js:572
    receiveInstance http://localhost:8000/main.js:726
    receiveInstantiationResult http://localhost:8000/main.js:744
    createWasm http://localhost:8000/main.js:767
    async* http://localhost:8000/main.js:6236

After applying a manual fix for the first issue:

Dropped file: /.glfw_dropped_files/test_0001.txt
Dropped file: /.glfw_dropped_files/test_0003.txt
Dropped file: /.glfw_dropped_files/test_0005.txt
Dropped file:
Uncaught RuntimeError: index out of bounds
    onloadend http://localhost:8000/main.js:5605
    onloadend http://localhost:8000/main.js:5605
    save http://localhost:8000/main.js:5595
    onDrop http://localhost:8000/main.js:5621
    _glfwInit http://localhost:8000/main.js:6110
    makeWrapper___PP http://localhost:8000/main.js:6257
    createExportWrapper http://localhost:8000/main.js:617
    callMain http://localhost:8000/main.js:6594
    doRun http://localhost:8000/main.js:6646
    run http://localhost:8000/main.js:6655
    setTimeout handler*run http://localhost:8000/main.js:6653
    removeRunDependency http://localhost:8000/main.js:572
    receiveInstance http://localhost:8000/main.js:726
    receiveInstantiationResult http://localhost:8000/main.js:744
    createWasm http://localhost:8000/main.js:767
    async* http://localhost:8000/main.js:6236

Version of emscripten/emsdk:
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 4.0.0 (97c7c2a)
clang version 20.0.0git (https:/github.com/llvm/llvm-project 322eb1a92e6d4266184060346616fa0dbe39e731)
Target: wasm32-unknown-emscripten
Thread model: posix

Failing command line in full:
emcc -s ENVIRONMENT=web -s USE_GLFW=3 -s MEMORY64=1 main.cpp -o main.html

main.cpp:

#include <emscripten.h>
#include <GLFW/glfw3.h>
#include <iostream>

int main(int, char**)
{
    glfwInit();

    GLFWwindow* window = glfwCreateWindow(1280, 720, "GLFW example", nullptr, nullptr);

    glfwSetDropCallback(window, [](GLFWwindow* window, int count, const char** paths) {
        for (int i = 0; i < count; ++i) {
            std::cout << "Dropped file: " << paths[i] << std::endl;
        }
    });

    emscripten_set_main_loop(glfwPollEvents, 0, true);

    glfwDestroyWindow(window);
    glfwTerminate();

    return 0;
}
@kripken
Copy link
Member

kripken commented Feb 14, 2025

This works in Chrome, so it is likely a Firefox issue. Perhaps Firefox 134 has not updated to the final spec? You may want to check a Firefox nightly build.

@sbc100
Copy link
Collaborator

sbc100 commented Feb 14, 2025

We have an interactive test called test_glfw_dropfile that I think we can you use test/verify this. You can run it in 64-bit mode using test/runner interactive64.test_glfw_dropfile

@oitel
Copy link
Contributor Author

oitel commented Feb 14, 2025

I've just checked it on Chromium version 133.0.6943.98 and got the same results (TypeError, then RuntimeError).
I don't know how does the test process dropping multiple files at once. Anyway I'll run it locally later and report to you.

sbc100 added a commit to sbc100/emscripten that referenced this issue Feb 14, 2025
Verified by running interactive64.test_glfw_dropfile locally.

Fixes: emscripten-core#23505
sbc100 added a commit to sbc100/emscripten that referenced this issue Feb 14, 2025
Verified by running interactive64.test_glfw_dropfile locally.

Fixes: emscripten-core#23505
@sbc100
Copy link
Collaborator

sbc100 commented Feb 14, 2025

Fix is in #23676

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 a pull request may close this issue.

3 participants