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

Bug: Exception when calling Windows.Gaming.Input.RawGameController.GetCurrentReading -> Cannot handle array marshalling for non-blittable type 'System.Boolean' #1928

Open
mikrause79 opened this issue Feb 19, 2025 · 1 comment

Comments

@mikrause79
Copy link

Description

This works for non-AoT. In AoT projects, calling Windows.Gaming.Input.RawGameController.GetCurrentReading is throwing an exception, Cannot handle array marshalling for non-blittable type: 'System.Boolean'.

The generated code appears to be:

    public ulong GetCurrentReading(bool[] buttonArray, GameControllerSwitchPosition[] switchArray, double[] axisArray)
    {
        return IRawGameControllerMethods.GetCurrentReading(_objRef_global__Windows_Gaming_Input_IRawGameController, buttonArray, switchArray, axisArray);
    }

The definition of GetCurrentReading in the IDL for the COM interface appears to be:

                HRESULT GetCurrentReading([in] UINT32 __buttonArraySize, [out] [size_is(__buttonArraySize)] boolean* buttonArray, [in] UINT32 __switchArraySize, [out] [size_is(__switchArraySize)] Windows.Gaming.Input.GameControllerSwitchPosition* switchArray, [in] UINT32 __axisArraySize, [out] [size_is(__axisArraySize)] DOUBLE* axisArray, [out] [retval] UINT64* timestamp);

Steps To Reproduce

  1. Create a WinAppSDK C# project, using Blank WinUI3, packaged template.
  2. Enable "PublishAot" on the project
  3. Make the following changes in app.xaml.cs:
       protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
        {
            Windows.Gaming.Input.RawGameController.RawGameControllerAdded += RawGameController_RawGameControllerAdded;
            m_window = new MainWindow();
            m_window.Activate();
        }

        private void RawGameController_RawGameControllerAdded(object? sender, Windows.Gaming.Input.RawGameController controller)
        {
            var buttons = new bool[controller.ButtonCount];
            var switches = new Windows.Gaming.Input.GameControllerSwitchPosition[controller.SwitchCount];
            var axes = new double[controller.AxisCount];

            var timestamp = controller.GetCurrentReading(buttons, switches, axes);
         }
  1. Plug in a gamepad or some other game controller

Expected Behavior

RawGameController.GetCurrentReading Should fill the array with button state.

Instead, it throws the following exception in WinRT.Runtime.dll:
Cannot handle array marshalling for non blittable type 'System.Boolean'.

Version Info

cswinrt 2.2.0.0
Microsoft.WindowsAppSDK 1.6.250205002
Microsoft.Windows.SDK.Net.Ref.Windows 10.0.19041.57

Additional Context

No response

@dongle-the-gadget
Copy link
Contributor

This will be fixed in #1843

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

No branches or pull requests

2 participants