Skip to content

Basic vector math broken in debugger only #126564

Closed

Description

@tetraminus

Description

I'm working on a game project right now, and I'm writing some relatively complex algorithms that heavily use Vectors. The actual code itself works fine but when i try to debug the code to find logical problems, the IDE debugger shows me wildly incorrect values for results of vector math operations(eg. Vector2.Zero * 1). This seems to happen with any vector, and any operation. Again, the actual values in the running code are fine, but the debugger shows something different.

Reproduction Steps

Vector2 vec = new Vector2(10, 10);
Console.WriteLine(vec * 1);

//some dummy code with a breakpoint

While stopped at breakpoint use ide tools to view result of operation directly (like hovering over the *) or run it in the repl.

Expected behavior

Displays the same number as whats printed to the console, <10,10>

Actual behavior

Displays the correct X value but a seemingly random Y value with no evident bound.

Image

Regression?

No response

Known Workarounds

No response

Configuration

Building for .NET 10 using .NET sdk 10.0.201
MacOS 26.5 ARM64
Reproducible in both Jetbrains Rider and VScode

Other information

No response

Activity

  1. added
    untriaged
    on Apr 5, 2026
  2. dotnet-policy-service commented on Apr 5, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-system-numerics
    See info in area-owners.md if you want to be subscribed.

  3. tannergooding commented on Apr 6, 2026

    @tannergooding
    Member

    This probably has to do with the respective debuggers, it does not reproduce in VS.

    CC. @tommcdon

  4. dotnet-policy-service commented on Apr 6, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag
    See info in area-owners.md if you want to be subscribed.

  5. Atulin commented on Apr 6, 2026

    @Atulin

    Odd that two different debuggers would have the same kind of bug tbh

  6. tannergooding commented on Apr 6, 2026

    @tannergooding
    Member

    Not really. The debuggers are likely failing to handle the specialized data type in a similar way. It is a value that contains 2 fields and gets placed into a single register. Further, it is a SIMD register and not a General Purpose register which entails its own other special handling and considerations.

  7. Atulin commented on Apr 6, 2026

    @Atulin

    The issue does not seem to occur on Windows, at least when it comes to the Rider debugger:

    Image
  8. huoyaoyuan commented on Apr 6, 2026

    @huoyaoyuan
    Member

    For completeness, it doesn't reproduce on Windows ARM64 with VS.

    Image
  9. removed
    untriaged
    on Jul 12, 2026
  10. added this to the 11.0.0 milestone on Jul 12, 2026
  11. steveisok commented on Jul 12, 2026

    @steveisok
    Member

    Root-caused this on macOS ARM64. It's a general HFA/HVA argument-marshalling bug in MethodDescCallSite::CallTargetWorker (src/coreclr/vm/callhelpers.cpp), not specific to SIMD or Vector2.

    That function hand-marshals arguments into the register save area for func-eval. The branch that expands a struct-passed-in-registers into individual register slots is only compiled for UNIX_AMD64_ABI / LOONGARCH64 / RISCV64 — ARM64 was never added. So HFA arguments passed by value in FP registers fall into the default packed CopyMemory, which places the fields contiguously instead of one field per NEON register slot. The callee ends up reading {field0, field2, garbage, …}, which is exactly the "first lane right, rest garbage" symptom.

    A few things worth noting:

    • It reproduces for any HFA argument, not just Vector2 — plain struct { float, float } and struct { double, double, double } are equally affected.
    • It's the argument path, not the return path. A method that builds an HFA purely from scalar args (MakeD3(1,2,3)) evaluates correctly; a method that takes an HFA (Scale(vec, 1)) does not.
    • It's "debugger only" because normal JIT-emitted calls and reflection invoke stubs don't use this manual marshalling path — debugger func-eval does.

    Fix is a small ARM64 branch that calls the already-existing ArgDestination::CopyHFAStructToRegister (the same helper CopyValueClassArgUnchecked already uses). With it, vec * 1 → <10, 10> and all the other cases evaluate correctly. The code is shared, so this defect affects Windows/Linux ARM64 as well — macOS is just where it was reported. PR incoming.


    Note

    This analysis was produced with the assistance of GitHub Copilot.

  12. self-assigned this
    on Jul 12, 2026
  13. added a commit that references this issue on Jul 14, 2026
    5d9e18e
  14. locked and limited conversation to collaborators on Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions