Explicitly free sprites on normal program termination
This commit is contained in:
parent
0e4b846590
commit
1e04b8fdca
@ -191,6 +191,7 @@ class Boss(Thread):
|
||||
# Must be called in the main thread as it manipulates signal handlers
|
||||
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
||||
signal.signal(signal.SIGTERM, signal.SIG_DFL)
|
||||
self.char_grid.destroy()
|
||||
|
||||
def shutdown(self):
|
||||
self.shutting_down = True
|
||||
|
||||
@ -159,6 +159,9 @@ class CharGrid:
|
||||
viewport=Size(self.width, self.height), clear_color=self.original_bg,
|
||||
cursor=self.default_cursor))
|
||||
|
||||
def destroy(self):
|
||||
self.sprites.destroy()
|
||||
|
||||
def initialize(self):
|
||||
self.default_bg, self.default_fg = self.original_bg, self.original_fg
|
||||
self.apply_opts(self.opts)
|
||||
|
||||
@ -487,6 +487,14 @@ DeleteTexture(PyObject UNUSED *self, PyObject *val) {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
DeleteBuffer(PyObject UNUSED *self, PyObject *val) {
|
||||
GLuint tex_id = (GLuint)PyLong_AsUnsignedLong(val);
|
||||
glDeleteBuffers(1, &tex_id);
|
||||
CHECK_ERROR;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
BlendFunc(PyObject UNUSED *self, PyObject *args) {
|
||||
int s, d;
|
||||
@ -559,6 +567,7 @@ int add_module_gl_constants(PyObject *module) {
|
||||
METH(ShaderSource, METH_VARARGS) \
|
||||
METH(CompileShader, METH_O) \
|
||||
METH(DeleteTexture, METH_O) \
|
||||
METH(DeleteBuffer, METH_O) \
|
||||
METH(GetString, METH_O) \
|
||||
METH(GetIntegerv, METH_O) \
|
||||
METH(Clear, METH_O) \
|
||||
|
||||
@ -16,7 +16,7 @@ from .fast_data_types import (
|
||||
glGetAttribLocation, glUseProgram, glBindVertexArray, GL_TEXTURE0,
|
||||
GL_TEXTURE1, glGetIntegerv, GL_MAX_ARRAY_TEXTURE_LAYERS, glBufferData,
|
||||
GL_MAX_TEXTURE_SIZE, glDeleteTexture, GL_TEXTURE_2D_ARRAY, glGenTextures,
|
||||
glBindTexture, glTexParameteri, GL_LINEAR, GL_CLAMP_TO_EDGE,
|
||||
glBindTexture, glTexParameteri, GL_LINEAR, GL_CLAMP_TO_EDGE, glDeleteBuffer,
|
||||
GL_TEXTURE_MAG_FILTER, GL_TEXTURE_MIN_FILTER, GL_TEXTURE_WRAP_S,
|
||||
GL_TEXTURE_WRAP_T, glGenBuffers, GL_R8, GL_RED, GL_UNPACK_ALIGNMENT, GL_UNSIGNED_BYTE,
|
||||
GL_STATIC_DRAW, GL_TEXTURE_BUFFER, GL_RGB32UI, glBindBuffer, glPixelStorei,
|
||||
@ -89,6 +89,15 @@ class Sprites:
|
||||
self.texture_id = tex
|
||||
glBindTexture(tgt, 0)
|
||||
|
||||
def destroy(self):
|
||||
if self.texture_id is not None:
|
||||
glDeleteTexture(self.texture_id)
|
||||
self.texture_id = None
|
||||
if self.buffer_texture_id is not None:
|
||||
glDeleteTexture(self.buffer_texture_id)
|
||||
if self.buffer_id is not None:
|
||||
glDeleteBuffer(self.buffer_id)
|
||||
|
||||
def ensure_state(self):
|
||||
if self.texture_id is None:
|
||||
self.realloc_texture()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user