emscripten-core / emscripten-core/emscripten

WebGL `GL_INVALID_OPERATION` in SDL2/SDL2_TFF

Open
#16,213 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

If this isn't the appropriate location to file this bug, please redirect me to the correct place.

**Version of emscripten/emsdk:**
```
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.3 (c06156773675b2cb437e41459c12d44bd9a8f235)
clang version 14.0.0 (https://github.com/llvm/llvm-project d8f929a567083a6b90264193f1e4476f6b77c5fe)
Target: wasm32-unknown-emscripten
Thread model: posix
````

**Description of problem**
While working with SDL/Emscripten/Rust, I've encountered a problem when rending text *and* rectangles (big ask, I know). As soon as I render text, I'm no longer able to render rectangles (`canvas.fill_rects` in Rust). These rectangles are drawn before (under, but not necessarily overlapping) the text. The text still renders. The issue seems to resolve itself if I render fewer rectangles, but the exact number is inconsistent. Any amount of text seems to cause the problem. Changing blending modes has no effect on the bug (bug still occurs). The error, best I can tell, happens _between frames_ (outside my code), while waiting for the browser to request the next animation frame. Increased memory allocation doesn't seem to help either. This problem does not occur when compiling for native hosts.

Originally, I was only experiencing the problem on OSX devices (iPhone, Mac+Chrome, Mac+Safari, Mac+Firefox), but I'm now able to consistently reproduce it on Windows (Windows+Chrome, Window+Edge) with a different error message. Haven't tested Linux.

A minimal reproducible example can be found here (doesn't have an option to compile for native): https://github.com/KyleMiles/Weird-SDL-Emscripten-Crash-Demo

The error I get from Mac+Chrome is:
```
[.WebGL-0x135865e00]GL ERROR :GL_INVALID_OPERATION : glDrawArrays: attempt to access out of range vertices in attribute 2
```

The error I get from Windows+Chrome and Windows+Edge is:
```
[.WebGL-] GL_INVALID_OPERATION: Internal error: 0x00000502: Vertex buffer is not big enough for the draw call.
```

This seems so fundamental that I can't help but think I'm using SDL2_TFF wrong, though I've done it [the only way I see how to](https://github.com/KyleMiles/Weird-SDL-Emscripten-Crash-Demo/blob/347719b092a9509a705ad922f35b37c63863b3fd/src/main.rs#L99-L120).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.