emscripten-core / emscripten-core/emscripten

GL.counter is never reset, so context destroy/create cycle grows table size forever

Open
#14,595 1 comment 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

Emscripten maintains a few JS tables to map from GLuint IDs (e.g. texture IDs) to the WebGL objects.

For example:
```js
var GL = {
counter: 1,
buffers: [],
programs: [],
framebuffers: [],
renderbuffers: [],
textures: []
// ...
}
```

These tables are indexed on the GLuint ID of the relevant object. The GLuint IDs are created by incrementing `GL.counter` whenever a new object is created. My problem is that I need to support the frequent destruction and recreation of GL contexts, but `GL.counter` is never reset. It only grows. This causes all of the tables inside the `GL` object to grow in size too.

I control all of the code inside my app, so I can say with 100% certainty when it is a safe time to reset the state of the GL object. Is there any way to do this right now?

If not, I am considering adding a function like
```js
// psuedo-code
emscripten_webgl_reset_gl_state() {
GL = {
counter: 1,
buffers: [],
// ...
}
}
```

Does this make sense?

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.