Skip to content

Commit

Permalink
[GL] fixed memory leak caused by missing onMakeCurrent callbacks when…
Browse files Browse the repository at this point in the history
… ContextHandle is disposed (destroy of UnsharedObjects/Framebuffer)
  • Loading branch information
luithefirst committed Jul 9, 2024
1 parent d938b5e commit 783315b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Aardvark.Rendering.GL/Core/ContextHandles.fs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ type ContextHandle(handle : IGraphicsContext, window : IWindowInfo) =
(handle |> unbox<IGraphicsContextInternal>).GetAddress(name)

member x.OnMakeCurrent(f : unit -> unit) =
if isDisposed then failwith "Failed to register OnMakeCurrent callback, the context is already disposed!"
Interlocked.CompareExchange(&onMakeCurrent, ConcurrentHashSet(), null) |> ignore
onMakeCurrent.Add f |> ignore

Expand Down Expand Up @@ -214,6 +215,15 @@ type ContextHandle(handle : IGraphicsContext, window : IWindowInfo) =

if lockTaken then
if not isDisposed then

// release potentially pending UnsharedObjects
let actions = Interlocked.Exchange(&onMakeCurrent, null)
if actions <> null then
x.Use(fun () ->
for a in actions do
a()
)

isDisposed <- true
debugOutput |> Option.iter (fun dbg -> dbg.Dispose())
onDisposed.Trigger()
Expand Down

0 comments on commit 783315b

Please sign in to comment.