Repository navigation
Don't leak the vertex shader if the fragment shader fails to compile - #1063
Open
Coastrnaut wants to merge 1 commit into
Open
Coastrnaut wants to merge 1 commit into
Coastrnaut wants to merge 1 commit into
Conversation
Shader::CompileProgram() compiled the vertex shader, then threw from the fragment shader compilation without deleting the vertex shader object. Every load of a preset whose shader the driver rejects leaked one shader object, including the driver memory backing it. Measured with an NVIDIA driver, alternating between such a preset and a working one for 200 switches: 100 leaked shader objects and 16 MB of heap growth before, no leaked objects and 2 MB after. Related to projectM-visualizer#1000.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Shader::CompileProgram()compiles the vertex shader, then the fragment shader. If the fragment shader fails to compile,CompileShader()throws and the already compiled vertex shader object is never deleted. This happens every time a preset whose (transpiled) shader doesn't compile is loaded, so apps that keep switching presets slowly accumulate shader objects and the driver memory behind them.This change deletes the vertex shader before rethrowing. The successful path and the thrown exception are unchanged.
Related to #1000. This removes one source of growth there, but not all of it: in my tests the rest of the growth is held by the GL driver (NVIDIA) and grows mainly the first time each new preset is used.
Measurements
Windows, RTX A6000, GL 3.3 core, presets switched with
projectm_playlist_play_next()while the preset is locked (the setup from #1000):Backwards compatibility
I loaded all 14,536 presets from cream-of-the-crop, en-d, milkdrop-original and projectm-classic one after another, rendering 30 frames each with fixed audio and frame times, and logged every
glCompileShader/glLinkProgramresult, failed preset loads, live shader objects and frame hashes. For the pixel comparison both builds had their random seeds fixed (a local patch only, identical on both sides).Unit tests pass. There's no new unit test because the test suite doesn't create a GL context.
#1026 contained the same change as part of a larger, closed PR.
Retested on current master (2026-11-12)
$$$ Royal - Mashup (257), which also renders differently between two runs of master.