Skip to content

CAN_ADDRESS_2GB vs emscripten_webgl_create_context #21278

Closed
@sbc100

Description

@sbc100

emscripten_webgl_create_context return EMSCRIPTEN_WEBGL_CONTEXT_HANDLE which is an opaque handle to the context.

Internally, the ends up either being small integer handle or, in multi-threaded build, it ends up being a pointer to small struct that we malloc:

var handle = _malloc({{{ 2 * POINTER_SIZE }}});
.

The problem is that emscripten_webgl_create_context is currently documented such that any value <= 0 is an error, and specifically that negative values are errrors. In CAN_ADDRESS_2GB mode, all pointers are greater than 2^31 and therefore show up as negative return values.

See https://emscripten.org/docs/api_reference/html5.h.html#c.emscripten_webgl_create_context

Possible solutions:

  1. Update emscripten_webgl_create_context such that all error return 0 and change the type of EMSCRIPTEN_WEBGL_CONTEXT_HANDLE to be unsigned.
  2. Create a new API and deprecate emscripten_webgl_create_context
  3. Always return a small integer handle from emscripten_webgl_create_context and then maintain a mapping to this mapped region separately.

(3) is the probably the safest, but comes with added overhead.

Of these options I think (1) is by far the easiest, but it has two possible downsides:

  1. In means that reason for context creation is no longer communicated via the return value. However, looking that the code we have to it looks like this feature is never used and all error cases return 0 for failure.
  2. Existing code that checks for the return code of this function might need updating? However I think it should be fine since all the current error paths already return 0, so existing code will already need to be checking for 0 (or < 1). Code that checks ctn < 0 could now get a compiler warning.. but such code would already be broken since it wouldn't handle the exist 0 error return codes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions