stride3d/stride · error · InvalidOperationException

Simulated GamePad does not exist

Error message

Simulated GamePad does not exist

What it means

InputSourceSimulated.RemoveGamePad requires the given GamePadSimulated to be one this source created and currently tracks in its gamePads list. Passing a game pad that is not tracked (never created via the source, already removed, or belonging to another source) throws InvalidOperationException after the membership check fails.

Solutions

  1. Only pass GamePadSimulated instances obtained from this source's CreateGamePad
  2. Guard with a Contains-style check or track removal with a bool before calling RemoveGamePad
  3. Call RemoveAllGamePads when tearing down instead of per-instance removal
  4. Keep references to removed pads out of active-use collections

Example fix

// before
source.RemoveGamePad(pad);
source.RemoveGamePad(pad); // second call throws
// after
if (pad != null && !removed.Contains(pad)) { source.RemoveGamePad(pad); removed.Add(pad); }
Defensive patterns

Strategy: validation

Validate before calling

bool tracked = sourceCreatedPads.Contains(pad);
if (tracked) source.RemoveGamePad(pad);

Try / catch

try { source.RemoveGamePad(pad); } catch (InvalidOperationException) { /* already removed */ }

Prevention

When it happens

Trigger: Calling RemoveGamePad with a GamePadSimulated that was not returned by this source's CreateGamePad, or calling it twice for the same instance (first RemoveGamePad removes it from gamePads).

Common situations: Tests that create simulated pads and tear down twice; holding stale references to a removed pad; mixing pads from two InputSourceSimulated instances.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/1f68d180d0043f5a. Report an issue: GitHub.

Appendix: source

Thrown at sources/engine/Stride.Input/Simulated/InputSourceSimulated.cs:49

            base.Dispose();
            keyboards.Clear();
            mice.Clear();
            gamePads.Clear();
            pointers.Clear();
        }

        public GamePadSimulated AddGamePad()
        {
            var gamePad = new GamePadSimulated(this);
            gamePads.Add(gamePad);
            RegisterDevice(gamePad);
            return gamePad;
        }

        public void RemoveGamePad(GamePadSimulated gamePad)
        {
            if (!gamePads.Contains(gamePad))
                throw new InvalidOperationException("Simulated GamePad does not exist");
            UnregisterDevice(gamePad);
            gamePads.Remove(gamePad);
        }

        public void RemoveAllGamePads()
        {
            foreach (var gamePad in gamePads)
                UnregisterDevice(gamePad);
            gamePads.Clear();
        }

        public MouseSimulated AddMouse()
        {
            var mouse = new MouseSimulated(this);
            mice.Add(mouse);
            RegisterDevice(mouse);
            return mouse;
        }

View on GitHub (pinned to 96fad776d2)