{"record":{"id":"7136a13253d70046","repo":"stride3d/stride","slug":"can-not-set-more-than-one-button-at-a-time","errorCode":null,"errorMessage":"Can not set more than one button at a time","messagePattern":"Can not set more than one button at a time","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Input/Simulated/GamePadSimulated.cs","lineNumber":31,"sourceCode":"            ProductId = new Guid(\"B540474D-F8CC-4D27-B57E-7E87272FD9E6\");\n            Id = Guid.NewGuid();\n            Source = source;\n            State = new GamePadState();\n        }\n\n        public override string Name { get; }\n        public override Guid Id { get; }\n        public override IInputSource Source { get; }\n        public override Guid ProductId { get; }\n        public override GamePadState State { get; }\n\n        private List<InputEvent> pendingEvents = new List<InputEvent>();\n\n        public void SetButton(GamePadButton button, bool state)\n        {\n            // Check for only 1 bit\n            if ((button & (button - 1)) != 0)\n                throw new InvalidOperationException(\"Can not set more than one button at a time\");\n\n            var buttonEvent = InputEventPool<GamePadButtonEvent>.GetOrCreate(this);\n            buttonEvent.Button = button;\n            buttonEvent.IsDown = state;\n            pendingEvents.Add(buttonEvent);\n        }\n\n        public void SetAxis(GamePadAxis axis, float value)\n        {\n            var axisEvent = InputEventPool<GamePadAxisEvent>.GetOrCreate(this);\n            axisEvent.Axis = axis;\n            axisEvent.Value = value;\n            pendingEvents.Add(axisEvent);\n        }\n\n        public override void Update(List<InputEvent> inputEvents)\n        {\n            ClearButtonStates();","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Input/Simulated/GamePadSimulated.cs#L13-L49","documentation":"GamePadSimulated.SetButton allows setting exactly one GamePadButton flag per call. The check (button & (button - 1)) != 0 fails when more than one bit is set in the flags value, so passing a combination like GamePadButton.A | GamePadButton.B throws InvalidOperationException. Passing GamePadButton.None (zero) also trips the check, since 0 & (0-1) == 0 is false — actually None passes, but any multi-flag value throws.","triggerScenarios":"Calling SetButton with a bitwise-OR of two or more GamePadButton flags, e.g. SetButton(GamePadButton.A | GamePadButton.B, true).","commonSituations":"Porting code that batches button states into a mask; loop code accumulating flags before a single SetButton call; misunderstanding the enum as a state mask rather than one-button-per-call API.","solutions":["Call SetButton once per button instead of OR-ing flags together","Iterate over the flags you need and issue one call per button","Use a helper that splits a mask into individual flags and calls SetButton for each"],"exampleFix":"// before\nsimulatedPad.SetButton(GamePadButton.A | GamePadButton.B, true);\n// after\nsimulatedPad.SetButton(GamePadButton.A, true);\nsimulatedPad.SetButton(GamePadButton.B, true);","handlingStrategy":"validation","validationCode":"if (button != 0 && (button & (button - 1)) != 0)\n    throw new ArgumentException(\"Set one button per SetButton call\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat GamePadButton as single-value in SetButton, not a bitmask","Write a SplitFlags helper that enumerates set bits and calls SetButton per bit","Never build composite button masks for this API"],"tags":["input","gamepad","simulated","flags-argument"],"backgroundTag":"invalid-argument-value","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}