Repository navigation
Upload texture pixel data with an unpack alignment of 1 - #1064
Open
Coastrnaut wants to merge 1 commit into
Open
Coastrnaut wants to merge 1 commit into
Coastrnaut wants to merge 1 commit into
Conversation
Texture data passed to projectM, e.g. from the texture load callback, is tightly packed, but GL_UNPACK_ALIGNMENT defaults to 4. For RGB (or 1/2 channel) images whose row size isn't a multiple of 4 bytes, the driver expects padded rows, so the texture is skewed and glTexImage2D reads past the end of the buffer, which can crash inside the driver. Set the alignment to 1 while uploading and restore the previous value afterwards, so the application's GL state isn't changed. Fixes projectM-visualizer#974
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.
Fixes #974
Texture data passed to projectM, e.g. from the texture load callback added in 4.2, is tightly packed, but
GL_UNPACK_ALIGNMENTdefaults to 4. For RGB (or 1/2 channel) images whose row size isn't a multiple of 4 bytes, the driver expects padded rows: the texture is skewed andglTexImage2Dreads past the end of the application's buffer. That's the crash inTexture::Texture()→_mesa_TexImage2D→memcpyfrom #974, which only happens with some cover images, depending on their width.Texture::Update(), the only place projectM uploads pixel data, now sets the alignment to 1 for the upload and restores the previous value afterwards, so the application's GL state is left alone.Testing
Windows, RTX A6000, GL 3.3 core. A small test app registers a texture load callback that returns a tightly packed image placed directly before a
PAGE_NOACCESSpage, so any read past its end crashes, and a preset that drawssampler_cover.With this PR the 501×500 and 333×200 RGB textures render identically to the same images given as RGBA (max pixel difference 0).
Backwards compatibility: I loaded all 14,536 presets from cream-of-the-crop, en-d, milkdrop-original and projectm-classic, with the preset folders as texture search path (loading the textures changed the output of ~7,000 presets, so image loading was exercised), and rendered 30 frames each with fixed audio, frame times and random seeds (the seeds were a local patch only, identical on both sides). Shader compile/link results, failed loads and the rendered frames are identical to master for every preset. All textures projectM creates itself are RGBA, where the alignment doesn't matter.
Unit tests pass. There's no new unit test because the test suite doesn't create a GL context.
Retested on current master (2026-11-12)