Skip to content

[rcore][RGFW] Abort when using emscripten_set_main_loop() instead of ASYNCIFY #5872

@preda

Description

@preda
  • I tested it on latest raylib version from master branch
  • I checked there is no similar issue already reported
  • [?] I checked the documentation on the wiki
  • [?] My code has no errors or misuse of raylib

Issue description

I compile for the Web. I do not want to use ASYNCIFY, so I use emscripten_set_main_loop() instead. I compare Web vs. WebRGFW. Web works but WebRGFW aborts with this stack trace:

abort http://localhost:8000/build-WebRGFW-Debug/hypertime.js:547
    _emscripten_sleep http://localhost:8000/build-WebRGFW-Debug/hypertime.js:7502
    RGFW_pollEvents http://localhost:8000/build-WebRGFW-Debug/hypertime.wasm:61424
    RGFW_window_checkEvent http://localhost:8000/build-WebRGFW-Debug/hypertime.wasm:61858
    PollInputEvents http://localhost:8000/build-WebRGFW-Debug/hypertime.wasm:69057
    EndDrawing http://localhost:8000/build-WebRGFW-Debug/hypertime.wasm:77383
    hypertime.wasm.doOneFrame() http://localhost:8000/build-WebRGFW-Debug/hypertime.wasm:9993
    callUserCallback http://localhost:8000/build-WebRGFW-Debug/hypertime.js:6520
    runIter http://localhost:8000/build-WebRGFW-Debug/hypertime.js:6640
    MainLoop_runner http://localhost:8000/build-WebRGFW-Debug/hypertime.js:6739

The source code I use is:

if __EMSCRIPTEN__
#include <emscripten.h>
#endif

#include "raylib.h"

void doOneFrame() {
    BeginDrawing();
    EndDrawing();
}

int main() {
    InitWindow(800, 600, "Hyper");

#if __EMSCRIPTEN__
    emscripten_set_main_loop(doOneFrame, 0, true);
#else
    /*
    while (!WindowShouldClose()) {
        doOneFrame();
    }
    */
#endif

    CloseWindow();
    return 0;
}

The output is:

INFO: Initializing raylib 6.1-dev
INFO: Platform backend: WEB (RGFW) (HTML5)
INFO: Supported raylib modules:
INFO:     > rcore:..... loaded (mandatory)
INFO:     > rlgl:...... loaded (mandatory)
INFO:     > rshapes:... loaded (optional)
INFO:     > rtextures:. loaded (optional)
INFO:     > rtext:..... loaded (optional)
INFO:     > rmodels:... loaded (optional)
INFO:     > raudio:.... loaded (optional)
INFO: DISPLAY: Device initialized successfully 
INFO:     > Display size: 800 x 600
INFO:     > Screen size:  800 x 600
INFO:     > Render size:  800 x 600
INFO:     > Viewport offsets: 0, 0
INFO: GL: Supported extensions count: 57
INFO: GL: OpenGL device information:
INFO:     > Vendor:   Mozilla
INFO:     > Renderer: Radeon R9 200 Series, or similar
INFO:     > Version:  OpenGL ES 2.0 (WebGL 1.0)
INFO:     > GLSL:     OpenGL ES GLSL ES 1.00 (WebGL GLSL ES 1.0)
INFO: GL: VAO extension detected, VAO functions loaded successfully
WARNING: GL: NPOT textures extension not found, limited NPOT support (no-mipmaps, no-repeat)
INFO: GL: DXT compressed textures supported
INFO: PLATFORM: DESKTOP (RGFW - WASMs): Initialized successfully
INFO: TEXTURE: [ID 2] Texture loaded successfully (1x1 | R8G8B8A8 | 1 mipmaps)
INFO: TEXTURE: [ID 2] Default texture loaded successfully
INFO: SHADER: [ID 3] Vertex shader compiled successfully
INFO: SHADER: [ID 4] Fragment shader compiled successfully
INFO: SHADER: [ID 5] Program shader loaded successfully
INFO: SHADER: [ID 5] Default shader loaded successfully
INFO: RLGL: Render batch vertex buffers loaded successfully in RAM (CPU)
INFO: RLGL: Render batch vertex buffers loaded successfully in VRAM (GPU)
INFO: RLGL: Default OpenGL state initialized successfully
INFO: TEXTURE: [ID 12] Texture loaded successfully (128x128 | GRAY_ALPHA | 1 mipmaps)
INFO: FONT: Default font loaded successfully (224 glyphs)
INFO: SYSTEM: Working Directory: /

Environment

Recent Firefox on Ubuntu 24.04.

Raylib was compiled such:

emcmake cmake -S . -B build-WebRGFW-Debug -DPLATFORM=WebRGFW -DCMAKE_BUILD_TYPE=Debug
cmake --build build-WebRGFW-Debug/ -j14
cp build-WebRGFW-Debug/raylib/libraylib.a build-lib/libraylib-WebRGFW-Debug.a

The code was compiled by passing this as CMake options (in cLion):
-S . -B build-WebRGFW-Debug -G Ninja -DPLATFORM=WebRGFW "-DCMAKE_TOOLCHAIN_FILE=~/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake"

And the same thing works with -DPLATFORM=Web instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions