Skip to content

fix video texture leaks - #2108

Merged
dimensionscape merged 6 commits into
openfl:developfrom
mrchaoss1:video-offthread-close
Oct 14, 2026
Merged

dimensionscape merged 6 commits into
openfl:developfrom
mrchaoss1:video-offthread-close

Conversation

@mrchaoss1

Copy link
Copy Markdown
Contributor

GL texture leak in VideoDecoder: if Close() ran outside the GL thread (for example when the GC finalized an unclosed decoder), its texture was dropped and never deleted.

GPU leak in MFVideoBackend: closing off the GL thread dropped the shared D3D11 textures, the WGL interop handles, the GL textures and the interop device without releasing them.

Both are now queued and released on the next texture read on the GL thread.

Data race: audioTime is written by the audio thread and read by the main thread, so it is now atomic.

mrchaoss1 and others added 6 commits October 14, 2026 19:57
The smoke test now closes its video on another thread, while its last
frame is still shown, and checks that its GL textures are gone once a
second video reads a frame on the GL thread. With hxcpp and HashLink, it
also drops a video without closing it and collects it on another thread.
Each backend now releases the GL objects it left from closing away from
the GL thread in its own ReleaseOrphans, called before a texture frame is
read there. This replaces a function pointer that was set under a lock and
read without one.

The lists of what was left are never destroyed, as exiting on Android and
Linux runs static destructors while threads can still be closing videos.

Media Foundation unlocks the frame that was shown when it closed before
releasing it, as closing on the GL thread does, rather than relying on
the driver to unregister a locked object.
A macOS backend closed or collected away from the GL thread kept its
textures and framebuffers, or forgot them when destroyed. They are now
deleted the next time a texture frame is read where their context is
current. iOS frames give back their own textures, so it leaves nothing.
A backend closed or collected away from the GL thread dropped its copy
texture, image texture, framebuffer, program, buffer and vertex array.
They are now deleted the next time a texture frame is read where their
context is current.
@dimensionscape

Copy link
Copy Markdown
Member

Looks good. Thanks!

@dimensionscape
dimensionscape merged commit 4f12e95 into openfl:develop Oct 14, 2026
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants