{"record":{"id":"ff6195b6bfdd772b","repo":"stride3d/stride","slug":"uicontrol-inputsourcewinforms","errorCode":null,"errorMessage":"uiControl","messagePattern":"uiControl","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Input/Windows/InputSourceWinforms.cs","lineNumber":44,"sourceCode":"        private KeyboardWinforms keyboard;\n        private MouseWinforms mouse;\n        private PointerWinforms pointer;\n\n        private IntPtr defaultWndProc;\n        private Win32Native.WndProc inputWndProc;\n\n        // My input devices\n        private readonly Control uiControl;\n        private InputManager input;\n\n        /// <summary>\n        /// Gets the value indicating if the mouse position is currently locked or not.\n        /// </summary>\n        public bool IsMousePositionLocked { get; protected set; }\n\n        public InputSourceWinforms(Control uiControl)\n        {\n            this.uiControl = uiControl ?? throw new ArgumentNullException(nameof(uiControl));\n        }\n\n        public override void Initialize(InputManager inputManager)\n        {\n            input = inputManager;\n\n            // Hook window proc\n            defaultWndProc = Win32Native.GetWindowLong(uiControl.Handle, Win32Native.WindowLongType.WndProc);\n            // This is needed to prevent garbage collection of the delegate.\n            inputWndProc = WndProc;\n            var inputWndProcPtr = Marshal.GetFunctionPointerForDelegate(inputWndProc);\n            Win32Native.SetWindowLong(uiControl.Handle, Win32Native.WindowLongType.WndProc, inputWndProcPtr);\n\n            // Do not register keyboard devices when using raw input instead\n            keyboard = new KeyboardWinforms(this, uiControl);\n            RegisterDevice(keyboard);\n\n            mouse = new MouseWinforms(this, uiControl);","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Input/Windows/InputSourceWinforms.cs#L26-L62","documentation":"InputSourceWinforms' constructor requires a WinForms Control used as the message pump target for mouse/keyboard/gamepad events. Passing null throws ArgumentNullException immediately. Without a control handle, Windows messages driving Stride input cannot be received.","triggerScenarios":"Calling new InputSourceWinforms(null) or passing a form/control reference that is still null at construction time.","commonSituations":"Constructing the input source before Application.Run / form creation; unit-testing the input pipeline without a real control; refactoring where the control field is initialized after the input source.","solutions":["Create the Form/Control first and pass the live instance to the constructor.","Assert the control is non-null and its handle exists before constructing the input source.","Delay input-source initialization until the UI control is available."],"exampleFix":"// before\nvar source = new InputSourceWinforms(controlField);\n// after\nif (controlField == null)\n    throw new InvalidOperationException(\"InputSourceWinforms requires an initialized Control.\");\nvar source = new InputSourceWinforms(controlField);","handlingStrategy":"validation","validationCode":"if (uiControl == null || uiControl.IsDisposed)\n    throw new InvalidOperationException(\"InputSourceWinforms requires a live Control.\");\nvar source = new InputSourceWinforms(uiControl);","typeGuard":"bool HasValidControl(Control c) => c != null && !c.IsDisposed;","tryCatchPattern":"try\n{\n    var source = new InputSourceWinforms(uiControl);\n}\ncatch (ArgumentNullException)\n{\n    // Defer input initialization until the form/control is created.\n}","preventionTips":["Construct the input source after form creation (e.g. in Form.Load, not before Main).","Pass the actual Form instance, not a lazily assigned field.","In tests, use a real control or skip window-backed input sources."],"tags":["winforms","null-argument","input","windows"],"backgroundTag":"null-argument","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}