Stop leaking textures and framebuffers in the OpenGL backend.

Closes #264.

Possibly addresses #286.
This commit is contained in:
Patrick Walton 2020-03-31 17:14:28 -07:00
parent bbcd371efc
commit 32a56eab85
2 changed files with 15 additions and 5 deletions

View File

@ -456,12 +456,15 @@ impl Device for GLDevice {
} }
#[inline] #[inline]
fn destroy_framebuffer(&self, framebuffer: Self::Framebuffer) -> Self::Texture { fn destroy_framebuffer(&self, mut framebuffer: Self::Framebuffer) -> Self::Texture {
let texture = GLTexture { let texture = GLTexture {
gl_texture: framebuffer.texture.gl_texture, gl_texture: framebuffer.texture.gl_texture,
size: framebuffer.texture.size, size: framebuffer.texture.size,
format: framebuffer.texture.format, format: framebuffer.texture.format,
}; };
unsafe {
gl::DeleteFramebuffers(1, &mut framebuffer.gl_framebuffer); ck();
}
mem::forget(framebuffer); mem::forget(framebuffer);
texture texture
} }
@ -991,6 +994,14 @@ pub struct GLTexture {
pub format: TextureFormat, pub format: TextureFormat,
} }
impl Drop for GLTexture {
fn drop(&mut self) {
unsafe {
gl::DeleteTextures(1, &mut self.gl_texture); ck();
}
}
}
pub struct GLTimerQuery { pub struct GLTimerQuery {
gl_query: GLuint, gl_query: GLuint,
} }

View File

@ -1140,12 +1140,11 @@ impl<D> TextureCache<D> where D: Device {
fn create_texture(&mut self, device: &mut D, format: TextureFormat, size: Vector2I) fn create_texture(&mut self, device: &mut D, format: TextureFormat, size: Vector2I)
-> D::Texture { -> D::Texture {
for index in 0..self.textures.len() { for index in 0..self.textures.len() {
if device.texture_size(&self.textures[index]) != size || if device.texture_size(&self.textures[index]) == size &&
device.texture_format(&self.textures[index]) != format { device.texture_format(&self.textures[index]) == format {
continue;
}
return self.textures.remove(index); return self.textures.remove(index);
} }
}
device.create_texture(format, size) device.create_texture(format, size)
} }