Deprecation notice: In Emscripten 1.37.20 and newer, C functions emscripten_set/get_canvas_size() are deprecated

916 views
Skip to first unread message

Jukka Jylänki

unread,
Aug 22, 2017, 3:09:52 AM8/22/17
to emscripte...@googlegroups.com
Hi all,

there are two Emscripten functions that are getting deprecated. In
#include <emscripten.h>, there are

void emscripten_set_canvas_size(int width, int height);
void emscripten_get_canvas_size(int *width, int *height, int *isFullscreen);

which should not be relied on in the future. The replacing functions are

EMSCRIPTEN_RESULT emscripten_set_canvas_element_size(const char
*target, int width, int height);
EMSCRIPTEN_RESULT emscripten_get_canvas_element_size(const char
*target, int *width, int *height);
EMSCRIPTEN_RESULT
emscripten_get_fullscreen_status(EmscriptenFullscreenChangeEvent
*fullscreenStatus);

that can be found in #include <emscripten/html5.h>

Instead of calling

emscripten_set_canvas_size(myWidth, myHeight);

call

EMSCRIPTEN_RESULT r = emscripten_set_canvas_element_size("#canvas",
myWidth, myHeight);
if (r != EMSCRIPTEN_RESULT_SUCCESS) /* handle error */

and instead of

int w, h, fs;
emscripten_get_canvas_size(&w, &h, &fs);

call

int w, h, fs;
EMSCRIPTEN_RESULT r = emscripten_get_canvas_element_size("#canvas", &w, &h);
if (r != EMSCRIPTEN_RESULT_SUCCESS) /* handle error */
EmscriptenFullscreenChangeEvent e;
r = emscripten_get_fullscreen_status(&e);
if (r != EMSCRIPTEN_RESULT_SUCCESS) /* handle error */
fs = e.isFullscreen;


This change expands C applications to be able to specify which canvas
they want to get the size from, instead of being hardcoded to access
the singleton "Module['canvas']" object. Also, the new functions will
be readily multithreading aware, which, due to a few overloaded
features, the old functions are not. For detailed information, see
https://github.com/kripken/emscripten/pull/5481.

The old functions will still be present for quite some time, though
unfortunately cannot function properly in multithreaded applications
when called from a pthread and OffscreenCanvas is being used.

Cheers,
Jukka

Floh

unread,
Aug 22, 2017, 9:24:16 AM8/22/17
to emscripten-discuss
Thanks for the heads-up! I was still using both functions in my code, replacing them now :)
Reply all
Reply to author
Forward
0 new messages