emscripten-core / emscripten-core/emscripten

SEGMENTATION FAULT with IMG_Load_RW

Open
#21,297 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

Get into **segmentation fault** while running the project in mix with SDL2 & Wasm Workers.
SDL2 works fine in config without Wasm Workers or pthreads but I need wasm workers to run sounds from miniaudio.h.
What it might be @sbc100 & @FrostKiwi ?

**Version of emscripten/emsdk:**
```
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.47 (431685f05c67f0424c11473cc16798b9587bb536)
clang version 18.0.0 (https://github.com/llvm/llvm-project 21030b9ab4487d845e29792063f5666d8c4b8e09)
Target: wasm32-unknown-emscripten
Thread model: posix
```

**Uncaught RuntimeError: Aborted(segmentation fault)**
```
Uncaught RuntimeError: Aborted(segmentation fault)
at abort (mob1x.js:862:40)
at segfault (mob1x.js:589:2)
at imports. (mob1x.js:8326:24)
at mob1x.wasm.SAFE_HEAP_STORE_i32_4_4 (mob1x.wasm:0xff1e37)
at SDL_RWtell (SDL_rwops.c:798)
at IMG_LoadPNG_RW (IMG_png.c:258)
at IMG_LoadTyped_RW (IMG.c:289)
at IMG_Load_RW (IMG.c:212)
at mob1x.wasm._KBTexture2D::InitWithImage(char const*, DIRECTORY_TYPES, bool) (https://mastersofbackgammon.net:5020/mob1x.wasm)
at mob1x.wasm._KBTextureStorage::LoadTextureFromFile(char const*, DIRECTORY_TYPES, bool) (https://mastersofbackgammon.net:5020/mob1x.wasm)
at mob1x.wasm._KBGUIFont::InitFonts() (https://mastersofbackgammon.net:5020/mob1x.wasm)
at mob1x.wasm._KBGUI::Init() (https://mastersofbackgammon.net:5020/mob1x.wasm)
```

**user callback triggered after runtime exited or application aborted. Ignoring.**
```
user callback triggered after runtime exited or application aborted. Ignoring. 2 [mob1x.js:4540:6](https://mastersofbackgammon.net:5020/mob1x.js)
callUserCallback https://mastersofbackgammon.net:5020/mob1x.js:4540
doCallback https://mastersofbackgammon.net:5020/mob1x.js:6848
reportReadyStateChange https://mastersofbackgammon.net:5020/mob1x.js:6869
onreadystatechange https://mastersofbackgammon.net:5020/mob1x.js:6703
(Async: EventHandlerNonNull)
fetchXHR https://mastersofbackgammon.net:5020/mob1x.js:6694
performUncachedXhr https://mastersofbackgammon.net:5020/mob1x.js:6874
onsuccess https://mastersofbackgammon.net:5020/mob1x.js:6786
(Async: EventHandlerNonNull)
fetchLoadCachedData https://mastersofbackgammon.net:5020/mob1x.js:6768
_emscripten_start_fetch https://mastersofbackgammon.net:5020/mob1x.js:6905
x https://mastersofbackgammon.net:5020/mob1x.js:8326
emscripten_fetch https://mastersofbackgammon.net:5020/mob1x.wasm:1527442
mob1x.wasm._KBHTTPQuery::Run() https://mastersofbackgammon.net:5020/mob1x.wasm:1548884
mob1x.wasm._KBHTTPManager::RunQuery(_KBHTTPQuery*) https://mastersofbackgammon.net:5020/mob1x.wasm:1838212
mob1x.wasm._KBHTTPManager::AddQuery(_KBHTTPQuery*) https://mastersofbackgammon.net:5020/mob1x.wasm:1837294
mob1x.wasm._KBHTTPManager::Get(char const*, _KBHTTPQueryCallback*, bool, int) https://mastersofbackgammon.net:5020/mob1x.wasm:614490
mob1x.wasm._KBResourceManager::CheckoutResourceVersion(int) https://mastersofbackgammon.net:5020/mob1x.wasm:1983027
mob1x.wasm._KBResourceManager::Init() https://mastersofbackgammon.net:5020/mob1x.wasm:883127
mob1x.wasm._KBCore::Init() https://mastersofbackgammon.net:5020/mob1x.wasm:879105
mob1x.wasm.initCore() https://mastersofbackgammon.net:5020/mob1x.wasm:14950189
mob1x.wasm.allocateSystem() https://mastersofbackgammon.net:5020/mob1x.wasm:96246
dynCall_v https://mastersofbackgammon.net:5020/mob1x.wasm:16697430
x https://mastersofbackgammon.net:5020/mob1x.js:8348
createExportWrapper https://mastersofbackgammon.net:5020/mob1x.js:884
browserIterationFunc https://mastersofbackgammon.net:5020/mob1x.js:6291
callUserCallback https://mastersofbackgammon.net:5020/mob1x.js:4544
runIter https://mastersofbackgammon.net:5020/mob1x.js:4618
Browser_mainLoop_runner https://mastersofbackgammon.net:5020/mob1x.js:4519
(Async: FrameRequestCallback)
requestAnimationFrame https://mastersofbackgammon.net:5020/mob1x.js:4858
Browser_mainLoop_scheduler_rAF https://mastersofbackgammon.net:5020/mob1x.js:1557
Browser_mainLoop_runner https://mastersofbackgammon.net:5020/mob1x.js:4523
(Async: FrameRequestCallback)
requestAnimationFrame https://mastersofbackgammon.net:5020/mob1x.js:4858
Browser_mainLoop_scheduler_rAF https://mastersofbackgammon.net:5020/mob1x.js:1557
Browser_mainLoop_runner https://mastersofbackgammon.net:5020/mob1x.js:4523
(Async: FrameRequestCallback)
requestAnimationFrame https://mastersofbackgammon.net:5020/mob1x.js:4858
Browser_mainLoop_scheduler_rAF https://mastersofbackgammon.net:5020/mob1x.js:1557
setMainLoop https://mastersofbackgammon.net:5020/mob1x.js:4531
_emscripten_set_main_loop https://mastersofbackgammon.net:5020/mob1x.js:6292
```

**CMakeLists.txt config**
```
(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(USE_FLAGS "-sUSE_ZLIB=1 -sUSE_SDL=2 -sUSE_SDL_IMAGE=2 -sSDL2_IMAGE_FORMATS=['png,jpg'] -O0 -flto -g -sWASM_WORKERS=1" CACHE STRING "Compilation flags" FORCE)

set(LINKING_FLAGS "--preload-file ${ASSETS_PATH}/assets@/assets -sFULL_ES2 -sWASM=1 -sFETCH=1 --use-preload-plugins -sEXIT_RUNTIME=1 -sALLOW_MEMORY_GROWTH=1 -sEXPORTED_FUNCTIONS=['_main','_photoTaken','_malloc','_setNotificationToken','_interceptPushNotification'] -sEXPORTED_RUNTIME_METHODS=[cwrap] -sFORCE_FILESYSTEM=1 -lidbfs.js -O0 -flto -g -sAUDIO_WORKLET=1 -sWASM_WORKERS=1 -sASYNCIFY -sASYNCIFY_STACK_SIZE=65536 -sUSE_SDL=2 -sUSE_SDL_IMAGE=2 -sSDL2_IMAGE_FORMATS=['png,jpg'] -sSAFE_HEAP=1" CACHE STRING "Linking flags" FORCE)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${USE_FLAGS}")

add_definitions(-DTARGET_WEB -DDEBUG -DMA_ENABLE_AUDIO_WORKLETS)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.