Skip to content

images: Change stbi_load() to use 4 chans#952

Open
RobLoach wants to merge 1 commit intoImmediate-Mode-UI:masterfrom
RobLoach:stbi_load-4-channel
Open

images: Change stbi_load() to use 4 chans#952
RobLoach wants to merge 1 commit intoImmediate-Mode-UI:masterfrom
RobLoach:stbi_load-4-channel

Conversation

@RobLoach
Copy link
Copy Markdown
Contributor

@RobLoach RobLoach commented May 2, 2026

Switches the stb image loads to default to 4 channels.

Fixes #950

@TomJGooding Like this?

@TomJGooding
Copy link
Copy Markdown
Contributor

TomJGooding commented May 2, 2026

Sorry but I really don't feel qualified to say whether this is the proper fix as mentioned in #950 (comment)!

But wouldn't this only work if we presuppose the DefaultDepth is 24? I don't fully understand what the switch (depth) is doing in nk_stbi_image_to_xsurf?

@sleeptightAnsiC
Copy link
Copy Markdown
Contributor

sleeptightAnsiC commented May 4, 2026

This is more of a workaround that hides the actual bug. Not the proper fix.

I haven't checked everything yet, but these two branches in nk_stbi_image_to_xsurf() are probably the root cause.

@TomJGooding mind sharing the file that caused it? "lena.png" ? EDIT: got one from https://github.com/mikolalysenko/lena/blob/master/lena.png

EDIT EDIT: another PR at #954

sleeptightAnsiC added a commit to sleeptightAnsiC/Nuklear that referenced this pull request May 5, 2026
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
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

3 participants