fix(core): fix memory alignment bug causing crash on odd-sized images#21
Closed
Calebsenm wants to merge 1 commit into
Closed
fix(core): fix memory alignment bug causing crash on odd-sized images#21Calebsenm wants to merge 1 commit into
Calebsenm wants to merge 1 commit into
Conversation
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.
Problem
When importing images (like
.bmpor.png) with non-standard or odd widths (e.g., 1003px), the preview display showed severe diagonal tearing/distortion, and the application would eventually freeze or crash.This happened because
Frame::generate_linesize_byteswas artificially aligning the pixel width to a multiple of 32((width + 31) & ~31). This created a massive mismatch with external libraries likeOpenImageIO, which read the exact raw pixels. The resulting stride mismatch caused rows to shift diagonally and led to a buffer overflow when rendering.Solution
Switched the alignment logic from pixels to bytes (which is the correct approach for hardware/GPU memory padding):
(row_bytes + 3) & ~3to keep the GPU happy and match industry standards.This fully resolves the distortion and eliminates the application freeze when working with arbitrary image resolutions.