Skip to content

Fix tracked-controls.controller undefined on controllerconnected after reconnect#5804

Open
vincentfretin wants to merge 1 commit intoaframevr:masterfrom
vincentfretin:fix-reconnect-controller-undefined
Open

Fix tracked-controls.controller undefined on controllerconnected after reconnect#5804
vincentfretin wants to merge 1 commit intoaframevr:masterfrom
vincentfretin:fix-reconnect-controller-undefined

Conversation

@vincentfretin
Copy link
Copy Markdown
Contributor

When a controller disconnects and reconnects, el.components['tracked-controls'].controller is undefined at the time the controllerconnected event fires, producing an error can't access gamepad on undefined on the haptics component at https://github.com/supermedium/superframe/blob/7439b2f77ade516077e8edfc41991ee0fc9d07a9/components/haptics/index.js#L31 so losing the vibrations when you put both controllers on the ground and picking them up again.

Root cause: The specific controller component (e.g. meta-touch-controls) registers its controllersupdated listener before tracked-controls' listener (because tracked-controls is created later during injectTrackedControls). On reconnect:

  1. The specific controller's controllersupdated handler fires first
  2. It calls checkControllerPresentAndSetupinjectTrackedControlssetAttribute('tracked-controls', ...) with unchanged data
  3. A-Frame skips update()/updateController() because the data hasn't changed
  4. controllerconnected is emitted with tracked-controls.controller still undefined
  5. tracked-controls' own controllersupdated listener fires after, but too late

Fix: In checkControllerPresentAndSetup, explicitly call trackedControls.updateController() before emitting controllerconnected. The check is skipped on first connect (tracked-controls doesn't exist yet) to avoid a redundant call.

…r reconnect

On controller reconnect, injectTrackedControls calls setAttribute('tracked-controls', ...)
with unchanged data so update/updateController is skipped. tracked-controls' own
controllersupdated listener fires too late because it was registered after the specific
controller component's listener. Explicitly call updateController before emitting
controllerconnected.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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

Successfully merging this pull request may close these issues.

1 participant