Skip to content

Conversation

@marcin-krystianc
Copy link

@marcin-krystianc marcin-krystianc commented Oct 28, 2025

Closes #1101

Previously, when creating 2D memory structures (Memory2D<T>, ReadOnlyMemory2D<T>, Span2D<T>, ReadOnlySpan2D<T>) with zero height or width, some constructors would take a shortcut by setting this = default. This approach had issues because it didn't properly preserve non-zero dimensions (e.g., a 4×0 or 0×7 structure would become 0×0). Additionally, the OverflowHelper.ComputeInt32Area method could return non-zero values when height=0 due to an invalid formula.

Solution

  • Removed the this = default shortcuts from all 2D memory structure constructors

  • Fixed calculation in OverflowHelper.ComputeInt32Area:

  • Added comprehensive tests to verify empty structures maintain correct dimensions

PR Checklist

  • Created a feature/dev branch in your fork (vs. submitting directly from a commit on main)
  • Based off latest main branch of toolkit
  • PR doesn't include merge commits (always rebase on top of our main, if needed)
  • Tested code with current supported SDKs
  • Tests for the changes have been added (for bug fixes / features) (if applicable)
  • Header has been added to all new source files (run build/UpdateHeaders.bat)
  • Contains NO breaking changes
  • Code follows all style conventions

Other information

@marcin-krystianc marcin-krystianc force-pushed the dev-20251028-span2d branch 2 times, most recently from 054dd66 to 4896877 Compare October 30, 2025 14:57
@marcin-krystianc marcin-krystianc force-pushed the dev-20251028-span2d branch 2 times, most recently from aba5858 to 9201b91 Compare November 6, 2025 14: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.

Wrong height and width of empty spans obtained from Span<T>.AsSpan2D.

1 participant