{"record":{"id":"cdc590ed1bbe542e","repo":"bevyengine/bevy","slug":"mapping-should-exist-from-connection","errorCode":null,"errorMessage":"mapping should exist from connection","messagePattern":"mapping should exist from connection","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/bevy_gilrs/src/gilrs_system.rs","lineNumber":76,"sourceCode":"                    });\n\n                    let event = GamepadConnectionEvent::new(\n                        entity,\n                        GamepadConnection::Connected {\n                            name: pad.name().to_string(),\n                            vendor_id: pad.vendor_id(),\n                            product_id: pad.product_id(),\n                        },\n                    );\n                    events.write(event.clone().into());\n                    connection_events.write(event);\n                }\n                EventType::Disconnected => {\n                    let gamepad = gamepads\n                        .id_to_entity\n                        .get(&gilrs_event.id)\n                        .copied()\n                        .expect(\"mapping should exist from connection\");\n                    let event =\n                        GamepadConnectionEvent::new(gamepad, GamepadConnection::Disconnected);\n                    events.write(event.clone().into());\n                    connection_events.write(event);\n                }\n                EventType::ButtonChanged(gilrs_button, raw_value, code) => {\n                    let button = convert_button(gilrs_button, code);\n                    let gamepad = gamepads\n                        .id_to_entity\n                        .get(&gilrs_event.id)\n                        .copied()\n                        .expect(\"mapping should exist from connection\");\n                    events.write(\n                        RawGamepadButtonChangedEvent::new(gamepad, button, raw_value).into(),\n                    );\n                    button_events.write(RawGamepadButtonChangedEvent::new(\n                        gamepad, button, raw_value,\n                    ));","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_gilrs/src/gilrs_system.rs#L58-L94","documentation":"This expect() panics inside bevy_gilrs's gilrs_event_system when a Disconnected event arrives for a gilrs gamepad id that has no entry in the GilrsGamepads.id_to_entity map. The map is populated at startup (gilrs_event_startup_system) and on Connected events; the Disconnected branch assumes the mapping exists. A missing mapping therefore indicates an internal invariant break: the device generated a disconnect the engine never saw a connection for (or the map was cleared).","triggerScenarios":"A gamepad disconnects whose Connected event was never processed through this system (e.g. GilrsPlugin added after startup systems ran, so gilrs_event_startup_system never mapped existing pads); the GilrsGamepads resource was cleared/reset mid-run; driver/OS quirks emitting disconnects for unknown device ids (Bluetooth controllers, hot-swap during sleep/wake).","commonSituations":"Adding GilrsPlugin at runtime after app startup instead of before; tests that inject gilrs events without the startup system; OS sleep/resume with a wireless controller; platform driver bugs replaying stale ids.","solutions":["Add GilrsPlugin during App construction (before startup), so gilrs_event_startup_system maps all initially connected pads.","Ensure GilrsGamepads / Gilrs resources are never cleared or replaced by user code or world-clearing routines.","Update Bevy — gaps in gilrs id mapping on disconnect are engine bugs; check the issue tracker for your version and upgrade.","If it reproduces deterministically with specific hardware, file a bevy_gilrs issue with the controller model and OS."],"exampleFix":"// before\napp.add_systems(Startup, gameplay_setup);\napp.add_plugins(GilrsPlugin); // added after startup ran once => unmapped pads can panic\n\n// after\napp.add_plugins(GilrsPlugin); // registers startup mapping for connected pads\napp.add_systems(Startup, gameplay_setup);","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Add GilrsPlugin during App construction so startup mapping runs for already-connected pads.","Never clear or replace the GilrsGamepads resource.","Run with the panic's backtrace (RUST_BACKTRACE=1) to confirm whether it is an engine bug, then update Bevy / report it."],"tags":["bevy","gilrs","gamepad","input","panic","disconnect"],"backgroundTag":"gamepad-id-mapping-missing","analyzedSha":"396ca727080776bd313bb892423b7d94e03b81b4","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}