Fix bugs in texture deletion

This commit is contained in:
Luke Benstead 2023-05-17 20:39:49 +01:00
parent c4c0bf4239
commit 462eb40d7a

View File

@ -559,15 +559,27 @@ void APIENTRY glGenTextures(GLsizei n, GLuint *textures) {
void APIENTRY glDeleteTextures(GLsizei n, GLuint *textures) { void APIENTRY glDeleteTextures(GLsizei n, GLuint *textures) {
TRACE(); TRACE();
while(n--) { gl_assert(TEXTURE_OBJECTS.element_size > 0);
TextureObject* txr = (TextureObject*) named_array_get(&TEXTURE_OBJECTS, *textures);
for(GLsizei i = 0; i < n; ++i) {
GLuint id = textures[i];
if(id == 0) {
/* Zero is the "default texture" and we never allow deletion of it */
continue;
}
TextureObject* txr = (TextureObject*) named_array_get(&TEXTURE_OBJECTS, id);
if(txr) { if(txr) {
/* Make sure we update framebuffer objects that have this texture attached */ gl_assert(txr->index == id);
_glWipeTextureOnFramebuffers(*textures);
if(txr == TEXTURE_UNITS[ACTIVE_TEXTURE]) { /* Make sure we update framebuffer objects that have this texture attached */
TEXTURE_UNITS[ACTIVE_TEXTURE] = NULL; _glWipeTextureOnFramebuffers(id);
for(GLuint j = 0; j < MAX_GLDC_TEXTURE_UNITS; ++j) {
if(txr == TEXTURE_UNITS[j]) {
TEXTURE_UNITS[j] = NULL;
}
} }
if(txr->data) { if(txr->data) {
@ -588,12 +600,14 @@ void APIENTRY glDeleteTextures(GLsizei n, GLuint *textures) {
free(txr->palette); free(txr->palette);
txr->palette = NULL; txr->palette = NULL;
} }
}
named_array_release(&TEXTURE_OBJECTS, *textures); named_array_release(&TEXTURE_OBJECTS, id);
*textures = 0; textures[i] = 0;
textures++; txr->index = 0;
}
} }
gl_assert(TEXTURE_OBJECTS.element_size > 0);
} }
void APIENTRY glBindTexture(GLenum target, GLuint texture) { void APIENTRY glBindTexture(GLenum target, GLuint texture) {