Skip to content

Upstream bugfixes 20261115 - #111

Open
heesup wants to merge 2 commits into
PlantSimulationLab:masterfrom
heesup:upstream-bugfixes-20261115
Open

heesup wants to merge 2 commits into
PlantSimulationLab:masterfrom
heesup:upstream-bugfixes-20261115

Conversation

@heesup

@heesup heesup commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Hello,

This PR fixes two Visualizer bugs. Each has a new selfTest; visualizer_tests passes 196/196 on Linux (WSL2, aarch64, GCC 15.2, Release).

1. Images added in window coordinates are drawn darker than the original

When I add an image to the Visualizer window as an overlay (addRectangleByCenter(..., "image.jpg", Visualizer::COORDINATES_WINDOW_NORMALIZED)), it looks much darker than the image file. The inset at the top right is a rendered camera image:

Screenshot 2026-11-15 124350

To check, I drew a uniform gray image (sRGB 128) the same way and read it back with printWindow(): it comes out as 55, which is exactly 128 converted to linear light. A photo shows the same darkening (Helios' own SkyDome_field.jpg; mean pixel value 119 in the file, 60 on master, 119 with this fix):

image image

Cause: with the linear pipeline on (the default), primaryShader.frag converts colors and textures from sRGB to linear, but converts back to sRGB only for 3D geometry (coordinateFlag==1). Window-coordinate geometry is converted to linear and never converted back.

Fix: the sRGB-to-linear conversion now also applies only when coordinateFlag==1, matching the output stage. 3D geometry is unchanged.

The default background gradient (textures/gradient_background.jpg) is drawn the same way, so it was also darker than its file. The fix brings it back to the file's colors (bottom row: file (100, 150, 199), master (32, 78, 146), with this fix (100, 150, 199)). In the comparison below, only the overlay and the background change; the 3D plants are identical:

image

2. Headless printWindow() crashes at a width that is not a multiple of 4

readOffscreenPixels() reads the image as GL_RGB into a tightly packed buffer without setting GL_PACK_ALIGNMENT, so for a width that is not a multiple of 4, glReadPixels writes past the end of the buffer. On master, a headless 381 x 64 capture aborts with free(): invalid next size (normal). The fix sets glPixelStorei(GL_PACK_ALIGNMENT, 1) before the read, as the other readback paths already do. The new test captures a uniform background at 381 x 64 and checks that every pixel reads back unchanged.

heesup and others added 2 commits November 15, 2026 12:55
…RGB values

With the linear pipeline on (the default), the fragment shader decodes vertex
colors and texture samples from sRGB to linear light, but the output stage
re-encodes to sRGB only for 3D geometry (coordinateFlag==1). Geometry added in
COORDINATES_WINDOW_NORMALIZED (an image overlay through addRectangleByCenter()
with a texture file, a colored 2D rectangle) was therefore decoded and never
re-encoded, and drawn too dark: a uniform sRGB 128 texture came out as 55.

The three decode sites now apply only to coordinateFlag==1, the same condition
as the output stage, so 2D geometry passes through in display space. 3D
geometry is unchanged.

Adds a selfTest that draws a uniform sRGB 128 texture in window coordinates
headless and checks the captured center pixel.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t are not a multiple of 4

Visualizer::readOffscreenPixels() read the offscreen framebuffer as GL_RGB into a tightly packed buffer
without setting GL_PACK_ALIGNMENT. At the default alignment of 4, glReadPixels pads each row to a multiple
of 4 bytes, so for any width not divisible by 4 it wrote up to 3 bytes per row past the end of the buffer
(corrupting the heap; a 381-pixel-wide capture aborted in malloc) and read every row skewed. The pack
alignment is now set to 1 before the read, as the other readback paths already do.

Adds a selfTest that captures a uniform background headless at a width of 381 as JPEG and checks it
reads back uniform.

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.

1 participant