Skip to content
This repository has been archived by the owner on Feb 17, 2022. It is now read-only.

"screen is not defined" when used with PROXY_TO_PTHREAD #110

Open
lwb4 opened this issue Mar 27, 2020 · 5 comments
Open

"screen is not defined" when used with PROXY_TO_PTHREAD #110

lwb4 opened this issue Mar 27, 2020 · 5 comments

Comments

@lwb4
Copy link

lwb4 commented Mar 27, 2020

When compiled with -s PROXY_TO_PTHREAD=1, calls to SDL_Init() fail with the error "screen is not defined".

This is important to me because proxying all socket commands through a local websocket server as described here is the only way I can get any networking to work in my project.

Here's my source file, poc.c:

#include "SDL.h"

int main() {
  SDL_Init(SDL_INIT_VIDEO);
  SDL_Quit();
}

And here's my commands to compile and run:

emcc poc.c -s USE_SDL=2 -s USE_PTHREADS=1 -s PROXY_POSIX_SOCKETS=1 -s PROXY_TO_PTHREAD=1 -o poc.html
python -m SimpleHTTPServer 5000

Open localhost:5000/poc.html in a browser, open the developer console, and you see this error:

poc.worker.js:175 Uncaught ReferenceError: screen is not defined
    at 37846 (http://localhost:2222/poc.js:1908:21)
    at _emscripten_asm_const_iii (http://localhost:2222/poc.js:1927:27)
    at wasm-function[968]:0x6a84c
    at wasm-function[852]:0x603e7
    at wasm-function[260]:0x3472
    at wasm-function[261]:0x35b0
    at wasm-function[258]:0x339a
    at wasm-function[259]:0x33a9
    at Module._main (http://localhost:2222/poc.js:9838:32)
    at ___call_main (http://localhost:2222/poc.js:2312:24)

From jakogut's comments on this site, it appears that the problem is simply that the screen object is not proxied to the new main thread. Relevant lines from video/emscripten/SDL_emscriptenvideo.c:

mode.w = EM_ASM_INT_V({
    return screen.width;
}); 

mode.h = EM_ASM_INT_V({
    return screen.height;
}); 

Indeed, the documentation on PROXY_TO_PTHREAD only says that the canvas object is proxied to the new main thread. How can we get screen proxied as well? I'm happy to contribute code, just need to be pointed in the right direction!

@Daft-Freak
Copy link
Member

Hmm, there was some discussion on this here #77 and some work on new APIs here emscripten-core/emscripten#9336.

The quickest solution is probably to switch to MAIN_THREAD_EM_ASM_INT. (Though a get_screen_size API would still be nice...)

@lwb4
Copy link
Author

lwb4 commented Mar 27, 2020

Oh nice, glad to see it's being worked on. I'll just use a workaround for now!

Daft-Freak added a commit that referenced this issue Apr 13, 2020
@danielknobe
Copy link

danielknobe commented Apr 13, 2020

This commits solves the problem but hidden error become visible.
The GL Context (GLctx) is undefined, when I try to run this short example:

	SDL_Init(SDL_INIT_VIDEO);

	auto mWindow = SDL_CreateWindow("Title",
	SDL_WINDOWPOS_UNDEFINED,
	SDL_WINDOWPOS_UNDEFINED,
	800, 600,
	0);

	auto mRenderer = SDL_CreateRenderer(mWindow, -1, SDL_RENDERER_ACCELERATED);

Stacktrace:

TypeError: Cannot read property 'getParameter' of undefined
    at emscriptenWebGLGet (http://localhost:6931/test.js:8035:28)
    at _emscripten_glGetIntegerv (http://localhost:6931/test.js:8136:7)
    at GLES2_CreateRenderer (wasm-function[5809]:0x131cc8)
    at SDL_CreateRenderer (wasm-function[5777]:0x12e043)
    at main (wasm-function[3132]:0x6f43a)
    at Module._main (http://localhost:6931/test.js:11010:32)
    at ___call_main (http://localhost:6931/test.js:2646:24)
    at __emscripten_thread_main (wasm-function[8646]:0x1cd812)
    at dynCall_ii (wasm-function[8678]:0x1cf7f4)
    at Object.Module.dynCall_ii (http://localhost:6931/test.js:11332:38)

@Daft-Freak
Copy link
Member

Daft-Freak commented Apr 14, 2020

Yeah, there are still other issues, that one can be fixed with -s OFFSCREEN_FRAMEBUFFER=1, but then you hit emscripten-core/emscripten#7684.

EDIT: The workaround from that issue needs a small tweak (emscripten_webgl_create_context("#canvas", &attr))

@danielknobe
Copy link

Yes this fixes that problem. Ty.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants