Skip to content

Commit befa7f5

Browse files
committed
Update EMSCRIPTEN_WEBGL_CONTEXT_HANDLE to handle full pointer range
In particular this changes the return type of `emscripten_webgl_create_context` such that negative values can no longer be returned. This allows pointers (specifically 32-bit pointers over 2gb) to be returned which is needed for pthread builds. The only valid failure return code for `emscripten_webgl_create_context` is now 0/NULL. As it happens this function never fails with anything except 0 so this should not be an impactful change. Split out from emscripten-core#21268 Fixes: emscripten-core#21278
1 parent c47d060 commit befa7f5

File tree

5 files changed

+12
-4
lines changed

5 files changed

+12
-4
lines changed

.circleci/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,7 @@ jobs:
819819
browser_2gb.test_emscripten_animate_canvas_element_size_manual_css
820820
browser_2gb.test_fulles2_sdlproc
821821
browser_2gb.test_cubegeom*
822+
browser_2gb.test_html5_webgl_create_context*
822823
"
823824
test-browser-chrome-wasm64-4gb:
824825
executor: bionic
@@ -834,6 +835,7 @@ jobs:
834835
browser64_4gb.test_fetch*
835836
browser64_4gb.test_emscripten_animate_canvas_element_size_manual_css
836837
browser64_4gb.test_fulles2_sdlproc
838+
browser64_4gb.test_html5_webgl_create_context*
837839
"
838840
test-browser-firefox:
839841
executor: bionic

ChangeLog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ See docs/process.md for more on how version tagging works.
2020

2121
3.1.54 (in development)
2222
-----------------------
23+
- The type of `EMSCRIPTEN_WEBGL_CONTEXT_HANDLE` we changed to be unsigned and
24+
the only valid error return value from `emscripten_webgl_create_context` is
25+
now zero. This allows `EMSCRIPTEN_WEBGL_CONTEXT_HANDLE` to hold a pointer
26+
to memory even in 2GB+ mode. Since `emscripten_webgl_create_context` never
27+
returns anything except zero for its errors today this change should not
28+
require any action. (#21268)
2329
- Added `--use-port` option to `emcc`. This option allows ports to be enabled
2430
by name and is designed to replace all existing `-sUSE_XXX` settings for
2531
ports. You can use `--show-ports` to get the list of available ports that

site/source/docs/api_reference/html5.h.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2086,7 +2086,7 @@ Functions
20862086
:type target: const char*
20872087
:param attributes: The attributes of the requested context version.
20882088
:type attributes: const EmscriptenWebGLContextAttributes*
2089-
:returns: On success, a strictly positive value that represents a handle to the created context. On failure, a negative number that can be cast to an |EMSCRIPTEN_RESULT| field to get the reason why the context creation failed.
2089+
:returns: On success, a non-zero value that represents a handle to the created context. On failure, 0.
20902090
:rtype: |EMSCRIPTEN_WEBGL_CONTEXT_HANDLE|
20912091
20922092

system/include/emscripten/html5_webgl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
extern "C" {
1515
#endif
1616

17-
typedef intptr_t EMSCRIPTEN_WEBGL_CONTEXT_HANDLE;
17+
typedef uintptr_t EMSCRIPTEN_WEBGL_CONTEXT_HANDLE;
1818

1919
typedef int EMSCRIPTEN_WEBGL_CONTEXT_PROXY_MODE;
2020
#define EMSCRIPTEN_WEBGL_CONTEXT_PROXY_DISALLOW 0

test/browser/webgl_create_context.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void loop() {
6060
assert(emscripten_webgl_get_current_context() == 0);
6161
context = emscripten_webgl_create_context("#canvas", &attrs);
6262

63-
assert(context > 0); // Must have received a valid context.
63+
assert(context != 0); // Must have received a valid context.
6464
res = emscripten_webgl_make_context_current(context);
6565
assert(res == EMSCRIPTEN_RESULT_SUCCESS);
6666
assert(emscripten_webgl_get_current_context() == context);
@@ -104,7 +104,7 @@ int main() {
104104

105105
assert(emscripten_webgl_get_current_context() == 0);
106106
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context = emscripten_webgl_create_context("#customCanvas", &attrs);
107-
assert(context > 0); // Must have received a valid context.
107+
assert(context != 0); // Must have received a valid context.
108108
EMSCRIPTEN_RESULT res = emscripten_webgl_make_context_current(context);
109109
assert(res == EMSCRIPTEN_RESULT_SUCCESS);
110110
assert(emscripten_webgl_get_current_context() == context);

0 commit comments

Comments
 (0)