Please nominate your Qt Champions for 2021! https://forum.qt.io/topic/132134/looking-for-the-2021-qt-champions

WebAssembly error/bug ?! float unrepresentable in integer range



  • I compiled a Qt app to WebAssembly using Emscripten. When I try to run the app in the browser I am seeing this output in the console of my browser, also see screenshot below it:

    exception thrown: RuntimeError: float unrepresentable in integer range,RuntimeError: float unrepresentable in integer range
        at wasm-function[32513]:0xbdce98
        at wasm-function[16435]:0x616a2a
        at wasm-function[6759]:0x230344
        at wasm-function[6760]:0x234104
        at wasm-function[16517]:0x6234ff
        at wasm-function[16221]:0x5fd749
        at wasm-function[10938]:0x3dfbe5
        at wasm-function[16137]:0x5efd48
        at wasm-function[10936]:0x3dd99c
        at wasm-function[16136]:0x5ef0b6
    

    webassembly-error.png

    Searching on the web for help on this I found that apparently it has something to do with 'trapping' (see link)
    WebAssembly Trapping

    As suggested I added the argument to avoid this trapping bug

    -mnontrapping-fptoint
    

    The way I added the argument was adding in my .pro file this line:

    QMAKE_CXXFLAGS += -mno-nontrapping-fptoint
    

    So when I 'qmake' using wasm (~/Qt/5.13.2/wasm_32/bin/qmake .) I can see the generated Makefile does indeed have the flag I added:

    ...
    CXXFLAGS      = -pipe -mno-nontrapping-fptoint 
    ...
    

    and then when I make I can see from the command output the argument is being passed in to em++ but for some reason it is ignored and the error still occurs after compiling and trying the app again in the browser:

    $ make
    em++ -c -pipe -mno-nontrapping-fptoint 
    ...
    ...
    clang++: warning: argument unused during compilation: '-mno-nontrapping-fptoint' [-Wunused-command-line-argument]
    ...
    ...
    

    I am using this version of Emscripten (sdk-fastcomp-1.38.27-64bit) and Qt 5.13.2

    $ em++ --version
    emcc (Emscripten gcc/clang-like replacement) 1.38.27 (commit 8f2f5e3435f6d0978469406a344a57a0d558deb1)
    
    $ clang++ --version
    clang version 6.0.1  (emscripten 1.38.27 : 1.38.27)
    
    

    This is a 'show-stopper' bug and I'm not sure how I can continue on. Thanks for your help guys!



  • I was able to get around this WebAssembly bug and I will post my findings here for the next poor soul that goes through this ordeal...

    I got it to work by manually adding

    -s BINARYEN_TRAP_MODE=clamp
    

    in the Makefile after executing qmake, this is what it looked like in the Makefile:

    LINK          = em++
    LFLAGS        = -s BINARYEN_TRAP_MODE=clamp -s WASM=1 -s FULL_ES2=1 -s USE_WEBGL2=1 -s NO_EXIT_RUNTIME=0 -s ERROR_ON_UNDEFINED_SYMBOLS=1 --bind -O3 -s ALLOW_MEMORY_GROWTH=1 -s TOTAL_MEMORY=64MB
    
    

    Played around a bit and found out I can achieve the same without having to add manually each time to the Makefile by adding in the .pro file the following Qmake Lflag

    wasm {
    QMAKE_LFLAGS += -s BINARYEN_TRAP_MODE=clamp
    }
    
    

    Shout out to @lorn-potter I know you would be interested in this solution probably!



  • BINARYEN_TRAP_MODE=clamp has been part of Qt WebAssembly since before is was integrated into Qt proper.
    Look at: mkspecs/wasm-emscripten/qmake.conf

    It is not needed for WASM_OBJECT_FILES, which is now the default, so it was removed in the 5.15 series.

    There was a typo (a missing + in +=) for a while that stopped it from actually being used


Log in to reply