emscripten icon indicating copy to clipboard operation
emscripten copied to clipboard

Assertion failed: target_thread, at: library_pthread.c,347,emscripten_async_queue_call_on_thread

Open legend-chen opened this issue 7 years ago • 9 comments

I actually spend a long time to figure out what happened, since i just updating sdk from 1.38.11 to 1.38.21.

The projects compiled by 1.38.21 with USE_PTHREADS and emscripten_webgl_create_context run correctly, but it failed with USE_PTHREADS and SDL.

please test sdl_gl_mapbuffers.c (in emscripten's tests)

sdl_gl_mapbuffers:
	emcc [email protected] -g3 -o [email protected] -s USE_PTHREADS=1 -s FULL_ES3=1 -lSDL -lGL 

maybe not InitWebGLTls in 1.38.21\system\lib\gl\webgl1.c

legend-chen avatar Dec 15 '18 09:12 legend-chen

I am trying to get over the issue with extral emscripten html5 codes. it works at least .

  EmscriptenWebGLContextAttributes attr;
  emscripten_webgl_init_context_attributes(&attr);
  EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_create_context(0, &attr);
  emscripten_webgl_make_context_current(ctx);

legend-chen avatar Dec 17 '18 06:12 legend-chen

Getting a similar error:

exception thrown: abort("Assertion failed: target_thread, at: /home/mbits/Development/emsdk/emscripten/1.38.21/system/lib/pthread/library_pthread.c,347,emscripten_async_queue_call_on_thread") at Error
    at jsStackTrace (http://localhost:6931/mRayWebClient.js:1262:13)
    at stackTrace (http://localhost:6931/mRayWebClient.js:1279:12)
    at abort (http://localhost:6931/mRayWebClient.js:19737:44)
    at ___assert_fail (http://localhost:6931/mRayWebClient.js:2076:7)
    at _emscripten_async_queue_call_on_thread (wasm-function[36432]:77)
    at _emscripten_async_queue_on_thread_ (wasm-function[36433]:826)
    at _glBufferData (wasm-function[36525]:212)

I am also using PThreads, SDL and GL ES 2.0

feliwir avatar Dec 17 '18 08:12 feliwir

@legend-chen any idea how to resolve this for SDL? Since that already creates a context for me.

feliwir avatar Dec 18 '18 13:12 feliwir

cc @juj

kripken avatar Dec 18 '18 17:12 kripken

@feliwir what I do is just creating a empty ctx before initing sdl, but this behavior is not always effective in all my projects. I expect available updating to fix this. good luck!

sometimes. need to do some required settings to ctx in my way.

EmscriptenWebGLContextAttributes attr;
emscripten_webgl_init_context_attributes(&attr);
attr.majorVersion = 2; attr.minorVersion = 0;
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_create_context(0, &attr);
emscripten_webgl_make_context_current(ctx);

legend-chen avatar Dec 19 '18 02:12 legend-chen

@kripken Can we reopen this? I'm encountering the same issue using SDL2 with proxy to pthread. This is currently a blocker for supporting SDL2 outside of the main thread. I have a branch with a test here: https://github.com/jakogut/emscripten/tree/sdl2-proxy-apis.

The problem is resolved with this patch:

diff --git a/tests/sdl2_gl_frames_swap.c b/tests/sdl2_gl_frames_swap.c
index aff19e881..f2283609b 100644
--- a/tests/sdl2_gl_frames_swap.c
+++ b/tests/sdl2_gl_frames_swap.c
@@ -6,7 +6,8 @@
  */
 
 #include <SDL.h>
-#include <emscripten.h>
+#include <emscripten/emscripten.h>
+#include <emscripten/html5.h>
 
 SDL_Window* window;
 SDL_Renderer* renderer;
@@ -30,6 +31,11 @@ void frame()
 
 int main()
 {
+    EmscriptenWebGLContextAttributes attr;
+    emscripten_webgl_init_context_attributes(&attr);
+    EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_create_context(0, &attr);
+    emscripten_webgl_make_context_current(ctx);
+
     SDL_Init(SDL_INIT_VIDEO);
     window = SDL_CreateWindow("test", 0, 0, 640, 480, SDL_WINDOW_OPENGL);
     renderer = SDL_CreateRenderer(window, 0, SDL_RENDERER_ACCELERATED);

Without the patch, running the test produces the following error:

Pthread aborting at Error
    at abort (http://localhost:8888/something.js:11945:70)
    at ___assert_fail (http://localhost:8888/something.js:1870:7)
    at emscripten_async_queue_call_on_thread (wasm-function[1373]:63)
    at emscripten_async_queue_on_thread_ (wasm-function[1389]:313)
    at glBufferData (wasm-function[1185]:139)
    at Draw (wasm-function[268]:197)
    at main (wasm-function[270]:295)
    at Module._main (http://localhost:8888/something.js:11257:32)
    at ___call_main (http://localhost:8888/something.js:2205:24)
    at __emscripten_thread_main (wasm-function[1390]:20)

Maybe something related to context creation isn't being properly proxied?

jakogut avatar Sep 11 '19 19:09 jakogut

Reopening.

Not sure what's going on here. I know @Beuc was looking at SDL2 with proxying, maybe this looks familiar?

kripken avatar Sep 11 '19 21:09 kripken

I didn't experiment much, I saw that screen wasn't proxied, asked for the progress status on the mailing list and directly @juj but got no answers, glad to see there is some activity. I don't remember hitting an assertion error.

Beuc avatar Sep 11 '19 21:09 Beuc

This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant.

stale[bot] avatar Sep 11 '20 01:09 stale[bot]