I am returning an array buffer from a function that I am then passing to gl.texImage2D. Doing this directly will not work:
- Code: Select all
const frame_data = fetch_raw_frame();
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 352, 208, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array(frame_data));
This will block forever in gl.texImage2D (no error is returned and the function also never returns).
If I slightly modify my code to this:
- Code: Select all
const frame_data = fetch_raw_frame();
const arr = new Uint8Array(frame_data);
const slice = arr.slice(0, frame_data.byteLength);
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 352, 208, 0, gl.RGBA, gl.UNSIGNED_BYTE, slice);
It works and the correct data is displayed.
The array buffer is created like this:
- Code: Select all
bool Execute(const CefString &name, CefRefPtr<CefV8Value> object, const CefV8ValueList &arguments, CefRefPtr<CefV8Value> &retval, CefString &exception) override {
pthread_mutex_lock(_video_shmem_mutex);
memcpy(_frame_data, _camera_frame_buffer, CAMERA_WIDTH * CAMERA_HEIGHT * 4);
pthread_mutex_unlock(_video_shmem_mutex);
retval = CefV8Value::CreateArrayBuffer(_frame_data, CAMERA_WIDTH * CAMERA_HEIGHT * 4, this);
return true;
}
Any ideas what could be causing this?
BR
Yanick