Skip to content

fix(x11): nk_stbi_image_to_xsurf corrupting memory when channels != bpl#954

Draft
sleeptightAnsiC wants to merge 1 commit intoImmediate-Mode-UI:masterfrom
sleeptightAnsiC:fix_x11_image_corruption
Draft

fix(x11): nk_stbi_image_to_xsurf corrupting memory when channels != bpl#954
sleeptightAnsiC wants to merge 1 commit intoImmediate-Mode-UI:masterfrom
sleeptightAnsiC:fix_x11_image_corruption

Conversation

@sleeptightAnsiC
Copy link
Copy Markdown
Contributor

Fixes: #950
Obsoletes: #952

See commit message and linked issues for more info.
This might be totally wrong so turning it into the DRAFT.

cc @TomJGooding , @RobLoach

@sleeptightAnsiC
Copy link
Copy Markdown
Contributor Author

sleeptightAnsiC commented May 5, 2026

Hi @riri ,

I'm pretty sure you're the most acknowledged with all X11/Xlib/XCB-related stuff. Mind taking a look here?

Something in my guts tells me nk_stbi_image_to_xsurf is simply wrong. The things it assumes and tries to do look strange in so many ways... but I kept them all.

One thing I did for testing was...

$ Xephyr :2 -screen 800x600x8 &
$ DISPLAY=:2 ./bin/demo

...which changed the result of DefaultDepth and allowed me to test other branches, but I'm not sure how correct this is.

@sleeptightAnsiC sleeptightAnsiC marked this pull request as draft May 5, 2026 03:58
nk_stbi_image_to_xsurf could corrupt memory when image channels
did not match screen surface depth. I fixed it by checking DefaultDepth
ahead of time and only then calling stbi_load* with previously
calculated channels value. I had to reorganize this function a bit.

TBH, I have no idea about Xlib and don't know what I'm doing,
and a lot of things in nk_stbi_image_to_xsurf was already questionable,
but after debugging and retesting, this makes the biggest sense to me.

Fixes: Immediate-Mode-UI#950
Obsoletes: Immediate-Mode-UI#952
@sleeptightAnsiC sleeptightAnsiC force-pushed the fix_x11_image_corruption branch from ce780cd to ef4953b Compare May 5, 2026 04:07
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.

Images in X11 backend only works with RGBA

1 participant