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

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

Closed
spider853 opened this issue Jan 17, 2024 · 4 comments · Fixed by #21362
Closed

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

spider853 opened this issue Jan 17, 2024 · 4 comments · Fixed by #21362

Comments

@spider853
Copy link

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();
@spider853
Copy link
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

@sbc100
Copy link
Collaborator

sbc100 commented Jan 17, 2024

I think this is likely a duplicate of #20992?

@spider853
Copy link
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)

@sbc100
Copy link
Collaborator

sbc100 commented Jan 17, 2024

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

@sbc100 sbc100 closed this as not planned Won't fix, can't repro, duplicate, stale Jan 17, 2024
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.

2 participants