Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A combination of Cast and Slice leads to AccessViolationException #674

Closed
1 of 4 tasks
mahalex opened this issue Apr 27, 2023 · 5 comments · Fixed by #675
Closed
1 of 4 tasks

A combination of Cast and Slice leads to AccessViolationException #674

mahalex opened this issue Apr 27, 2023 · 5 comments · Fixed by #675
Assignees
Labels
bug 🐛 An unexpected issue that highlights incorrect behavior Good first issue 💯 Issues identified as good for first-time contributors high-performance 🚂 Issues/PRs for the HighPerformance package

Comments

@mahalex
Copy link

mahalex commented Apr 27, 2023

Describe the bug

The following code throws System.AccessViolationException:

            int height = 720;
            int width = 1280;
            byte[] storage = new byte[width * height * sizeof(int)];
            Memory2D<int> data = storage
                .AsMemory()
                .Cast<byte, int>()
                .AsMemory2D(height: height, width: width);
            Memory2D<int> slice = data.Slice(
                row: height / 2,
                column: 0,
                height: height / 2,
                width: width);
            int total = 0;
            foreach (int v in slice.Span)
            {
                total += v;
            }

Regression

No response

Steps to reproduce

Create a project targeting net7.0, paste the above code into the `Main` method, run it.

Expected behavior

The code is supposed to calculate a sum of all values in the slice (in this case, 0).

Screenshots

image

IDE and version

VS 2022

IDE version

17.4.4

Nuget packages

  • CommunityToolkit.Common
  • CommunityToolkit.Diagnostics
  • CommunityToolkit.HighPerformance
  • CommunityToolkit.Mvvm (aka MVVM Toolkit)

Nuget package version(s)

8.2.0

Additional context

The problem disappears when there's no Cast() (so, we are summing over a Span of bytes). It also disappears when there's no Slice() (so, we are summing over data instead of slice).

Help us help you

No, just wanted to report this

@mahalex mahalex added the bug 🐛 An unexpected issue that highlights incorrect behavior label Apr 27, 2023
@Sergio0694 Sergio0694 added the high-performance 🚂 Issues/PRs for the HighPerformance package label Apr 27, 2023
@Sergio0694 Sergio0694 self-assigned this Apr 27, 2023
@Sergio0694
Copy link
Member

Good catch!! Thank you 😄

@Sergio0694 Sergio0694 added the Good first issue 💯 Issues identified as good for first-time contributors label Apr 27, 2023
@ChristophLindemann
Copy link

@Sergio0694 when will this be released?

@ChristophLindemann
Copy link

@Sergio0694 do you have some ETA of when this will be released? I can see you added it to 8.2.1, but I could not find a planned/estimated release date for that?

It's just so I can decide if I should implement a workaround for this, or if I can wait for 8.2.1.

@Sergio0694
Copy link
Member

I don't have an exact ETA just yet, but tentatively I'd say probably around the first half of June or so?
Can you use a nightly package from main in the meantime? The feed is this one:
https://pkgs.dev.azure.com/dotnet/CommunityToolkit/_packaging/CommunityToolkit-MainLatest/nuget/v3/index.json

@ChristophLindemann
Copy link

I guess, I could use one of the nightly builds for now.

I will use 8.2.1-build.2

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 An unexpected issue that highlights incorrect behavior Good first issue 💯 Issues identified as good for first-time contributors high-performance 🚂 Issues/PRs for the HighPerformance package
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants