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

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

@lwb4

Description

@lwb4

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions