GL Texture memory leak in Chapter 28: Ray Tracing Inhomogeneous Volumes
mmmovania opened this issue · comments
There is a potential GL texture memory leak in the code. It generates a new texture object each frame (line 459-462).
Solution:
Two additions in the code should do it :)
- Add the following code after line 431
kernel_params.iteration = 0;
//allocate texture once
glBindTexture(GL_TEXTURE_2D, display_tex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
- Replace glTexImage2D and parameter setting calls (lines 459-462) with the following glTexSubImage2D call,
glTexSubImage2D(GL_TEXTURE_2D, 0, 0,0, width, height, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
Thanks! I am checking with the author.
Reply from Matthias Raab:
... as far as I see the proposed fixes are definitely cleaner and should be applied.
(I don't think it's an actual memory leak, but there's a chance that drivers don't handle that too efficiently)
So, I've applied your solution - thanks for pointing it out.