emscripten-core / emscripten-core/emscripten
error: INVALID_OPERATION: texImage2D: no texture bound to target
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
The following example code has an error:
```
UINT __stdcall ThreadFuncEx2(LPVOID param)
{
EmscriptenWebGLContextAttributes attr;
emscripten_webgl_init_context_attributes(&attr);
attr.enableExtensionsByDefault = 1;
attr.premultipliedAlpha = 0;
attr.majorVersion = 1;
attr.minorVersion = 0;
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx1 = emscripten_webgl_create_context("#canvas", &attr);
emscripten_webgl_make_context_current(ctx1);
const int x = 100;
const int y = 100;
SHORT p2[x * y] = {0};
SHORT* pDestAdd = p2;
// this line yield an error (see the screen shot below).
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, x, y, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, p2);
/////
while (1)
{
Sleep(1000);
glClearColor(((float)rand()) / RAND_MAX, ((float)rand()) / RAND_MAX, ((float)rand()) / RAND_MAX, 1);
}
return 0;
}
int main()
{
emscripten_set_canvas_element_size("#canvas", SCREEN_WIDTH, SCREEN_HEIGHT);
EmscriptenWebGLContextAttributes attr;
emscripten_webgl_init_context_attributes(&attr);
attr.alpha = attr.depth = attr.stencil = attr.antialias = attr.preserveDrawingBuffer = attr.failIfMajorPerformanceCaveat = 0;
attr.enableExtensionsByDefault = 1;
attr.premultipliedAlpha = 0;
attr.majorVersion = 1;
attr.minorVersion = 0;
ctx = emscripten_webgl_create_context("#canvas", &attr);
emscripten_webgl_make_context_current(ctx);
GLenum err = glewInit();
///
/// here some drawing job.
///
pthread_attr_t attr1;
pthread_attr_init(&attr1);
pthread_t thread;
int rct = pthread_create(&thread, &attr1, (void* (*)(void*))ThreadFuncEx2, (void*)1);
return 0;
}
```
screen shote error:

**Version of emscripten/emsdk:**
emcc 3.1.9
OS - Windows.
Browser - Chrome
**Link flags:**
-s OFFSCREENCANVAS_SUPPORT -s OFFSCREEN_FRAMEBUFFER -s WASM_WORKERS -profiling -g -s EXPORTED_RUNTIME_METHODS=ccall,cwrap -s EXPORTED_FUNCTIONS=_main,_NativeTestThreads --preload-file com.skyline.terraexplorer -s OFFSCREEN_FRAMEBUFFER=1 -s OFFSCREENCANVAS_SUPPORT=1 -s WASM_BIGINT -fexceptions -s WASM_BIGINT -s FETCH=1 --bind -fexceptions -s USE_PTHREADS -s PTHREAD_POOL_SIZE=5 -s ALLOW_MEMORY_GROWTH=1
Contributor guide
Assessment
This issue has not been assessed yet.