Skip to content

fix(core): fix memory alignment bug causing crash on odd-sized images#21

Closed
Calebsenm wants to merge 1 commit into
OakVideoEditorCommunity:mainfrom
Calebsenm:fix/stride-alignment-crash
Closed

fix(core): fix memory alignment bug causing crash on odd-sized images#21
Calebsenm wants to merge 1 commit into
OakVideoEditorCommunity:mainfrom
Calebsenm:fix/stride-alignment-crash

Conversation

@Calebsenm

Copy link
Copy Markdown
  • Replaced pixel-based 32-pixel stride alignment with a byte-based 4-byte alignment in generate_linesize_bytes.
  • Fixed image distortion (diagonal tearing) and subsequent buffer overflow crashes when importing images with non-standard or odd widths.

Problem

When importing images (like .bmp or .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_bytes was artificially aligning the pixel width to a multiple of 32 ((width + 31) & ~31). This created a massive mismatch with external libraries like OpenImageIO, 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):

  1. Calculate the raw row size in bytes first.
  2. Align the final byte count to a 4-byte boundary (row_bytes + 3) & ~3 to keep the GPU happy and match industry standards.

This fully resolves the distortion and eliminates the application freeze when working with arbitrary image resolutions.

@Calebsenm Calebsenm closed this Jul 19, 2026
@Calebsenm
Calebsenm deleted the fix/stride-alignment-crash branch July 19, 2026 00: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.

1 participant