Skip to content

Upload texture pixel data with an unpack alignment of 1 - #1064

Open
Coastrnaut wants to merge 1 commit into
projectM-visualizer:masterfrom
Coastrnaut:fix/texture-upload-unpack-alignment
Open

Coastrnaut wants to merge 1 commit into
projectM-visualizer:masterfrom
Coastrnaut:fix/texture-upload-unpack-alignment

Conversation

@Coastrnaut

@Coastrnaut Coastrnaut commented Nov 8, 2026 •

Copy link
Copy Markdown

Fixes #974

Texture data passed to projectM, e.g. from the texture load callback added in 4.2, 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: the texture is skewed and glTexImage2D reads past the end of the application's buffer. That's the crash in Texture::Texture() → _mesa_TexImage2D → memcpy from #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_NOACCESS page, so any read past its end crashes, and a preset that draws sampler_cover.

Image master this PR
501×500, 3 channels crash OK
333×200, 3 channels crash OK
257×129, 1 channel crash OK
500×500, 3 channels OK OK
501×500 / 333×200, 4 channels OK OK

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)

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

No deployments
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.

[APP BUG] Tauon segfaults if libprojectM is initialized on a specific cover image

1 participant