Skip to content

Event.detail is used even if is not set (like in the case of Resize event) #21091

Closed

Description

@spider853

Please include the following in your bug report:

Version of emscripten/emsdk:
Please include the output emcc -v here

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.51 (c0c2ca1)
clang version 18.0.0git (https://github.com/llvm/llvm-project f2464ca317bfeeedddb7cbdea3c2c8ec487890bb)
Target: wasm32-unknown-emscripten
Thread model: posix

Build command line:
emcc --bind --profiling -g -sASSERTIONS=2
-sSHARED_MEMORY
-s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1
-L/J/FFMPEG_SRC/FFmpeg/testcpp/libs/ffmpeg/lib
-I/J/FFMPEG_SRC/FFmpeg/testcpp/libs/ffmpeg/include
-s EXPORTED_RUNTIME_METHODS="[FS, cwrap, ccall, getValue, setValue, writeAsciiToMemory, run]"
-lx264 -lx265 -lvpx -lmp3lame -logg -ltheora -lvorbis -lvorbisenc -lvorbisfile -lopus -lz -lwebp -lfreetype -lfribidi -lharfbuzz -lass -lzimg -lm
-lavcodec -lavfilter -lavformat -lavutil -lswresample -lswscale
-Wno-deprecated-declarations
-sWASM_BIGINT
-sUSE_SDL=2
-sINITIAL_MEMORY=32MB -sALLOW_MEMORY_GROWTH
-s USE_PTHREADS=1 -sPTHREAD_POOL_SIZE=4 -sPTHREAD_POOL_SIZE_STRICT=2 -sSTACK_OVERFLOW_CHECK=2
-o www/mp4info.js
mp4info-wrapper.cpp

** The Issue **

I'm using SDL2 to output a frame to a texture.
Now it seems like emscripten checks events with Event.detail which is fine for MouseEvents and other usual events.
But if you resize the window it will trigger the function with a Event that doesn't have a detail member causing an error a detail is undefined:

** Callstack **
image

** UIEventHandlerFunc **

 var uiEvent = targetThread ? _malloc(36) : JSEvents.uiEvent;
  GROWABLE_HEAP_I32()[((uiEvent) >> 2)] = e.detail; // <-------------- Another access
  checkInt32(e.detail); // <-------------- Here is the access
  GROWABLE_HEAP_I32()[(((uiEvent) + (4)) >> 2)] = b.clientWidth;
  checkInt32(b.clientWidth);
  GROWABLE_HEAP_I32()[(((uiEvent) + (8)) >> 2)] = b.clientHeight;
  checkInt32(b.clientHeight);

** Handler func **

 var jsEventHandler = function jsEventHandler(event) {
   ++JSEvents.inEventHandler;
   JSEvents.currentEventHandler = eventHandler;
   JSEvents.runDeferredCalls();
   eventHandler.handlerFunc(event); // < ----------------------------- The error is here as the event resize doesn't have detail
   JSEvents.runDeferredCalls();
   --JSEvents.inEventHandler;
  };
  if (eventHandler.callbackfunc) {
   eventHandler.eventListenerFunc = jsEventHandler;
   eventHandler.target.addEventListener(eventHandler.eventTypeString, jsEventHandler, eventHandler.useCapture);
   JSEvents.eventHandlers.push(eventHandler);
   JSEvents.registerRemoveEventListeners();

Activity

  1. spider853 commented on Jan 17, 2024

    @spider853
    Author

    SDL_init code:

    void runSDL() {
        SDL_Init(SDL_INIT_VIDEO);
        SDL_CreateWindowAndRenderer(512, 512, 0, &window, &renderer);
        //surface = SDL_CreateRGBSurface(0, 512, 512, 32, 0, 0, 0, 0);
        
        emscripten_set_main_loop(drawFramePixels, 0, 0); // 0, 1
    }

    drawFramePixels only draws a surface, no event polling

  2. sbc100 commented on Jan 17, 2024

    @sbc100
    Collaborator

    I think this is likely a duplicate of #20992?

  3. spider853 commented on Jan 17, 2024

    @spider853
    Author

    I think this is likely a duplicate of #20992?

    looks pretty similar, also related to e.detail not being a number (in my case undefined)

  4. sbc100 commented on Jan 17, 2024

    @sbc100
    Collaborator

    OK, closing in favor of #20992, which will hopefully get fixed soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions