Skip to content

Commit

Permalink
handle Texture explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
ffreyer committed Jan 2, 2025
1 parent fb4bf07 commit e8bf0fe
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions GLMakie/src/GLAbstraction/GLTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -523,3 +523,7 @@ end
function free(x::GLVertexArray)
@assert x.id == 0 "Must be freed explicitly"
end

function free(x::Texture)
@assert x.id == 0 "Must be freed explicitly"
end
2 changes: 1 addition & 1 deletion GLMakie/src/gl_backend.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function cleanup_texture_atlas!(context)
for (atlas, ctx) in to_delete
tex, func = pop!(atlas_texture_cache, (atlas, ctx))
Makie.remove_font_render_callback!(atlas, func)
GLAbstraction.free(tex)
GLAbstraction.unsafe_free(tex)
end
return
end
Expand Down
10 changes: 10 additions & 0 deletions GLMakie/src/glwindow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@ Makie.@noconstprop function GLFramebuffer(context, fb_size::NTuple{2, Int})
)::GLFramebuffer
end

function destroy!(fb::GLFramebuffer)
for tex in values(fb.buffers)
GLAbstraction.unsafe_free(tex)
end
id = [fb.id]
glDeleteFramebuffers(1, id)
fb.id = 0
return
end

function Base.resize!(fb::GLFramebuffer, w::Int, h::Int)
(w > 0 && h > 0 && (w, h) != size(fb)) || return
for (name, buffer) in fb.buffers
Expand Down
1 change: 0 additions & 1 deletion GLMakie/src/precompiles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ let
screen = Screen(Scene(), config; visible=false, start_renderloop=false)
close(screen)

empty!(atlas_texture_cache)
closeall(; empty_shader=false)
@assert isempty(SCREEN_REUSE_POOL)
@assert isempty(ALL_SCREENS)
Expand Down
1 change: 1 addition & 0 deletions GLMakie/src/screen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ function destroy!(screen::Screen)
GLFW.SetWindowRefreshCallback(window, nothing)
GLFW.SetWindowContentScaleCallback(window, nothing)
foreach(destroy!, screen.postprocessors) # before texture atlas, otherwise it regenerates
destroy!(screen.framebuffer)
cleanup_texture_atlas!(window)
GLAbstraction.unsafe_free(screen.shader_cache)
destroy!(window)
Expand Down

0 comments on commit e8bf0fe

Please sign in to comment.