Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CT: Assertion failed: Attempted to attach to an already attached pointer #250

Closed
pixelzoom opened this issue Oct 5, 2022 · 5 comments
Closed

Comments

@pixelzoom
Copy link
Contributor

pixelzoom commented Oct 5, 2022

This is undoubtedly related to #249, where KeyboardDragListeners were added for alt input.

Note that CT is reporting this for ph-scale-basics, but not ph-scale. But 99.9% of the code lives in ph-scale.

ph-scale-basics : interactive-description-fuzzBoard : unbuilt
https://bayes.colorado.edu/continuous-testing/ct-snapshots/1664913638509/ph-scale-basics/ph-scale-basics_en.html?continuousTest=%7B%22test%22%3A%5B%22ph-scale-basics%22%2C%22interactive-description-fuzzBoard%22%2C%22unbuilt%22%5D%2C%22snapshotName%22%3A%22snapshot-1664913638509%22%2C%22timestamp%22%3A1664919674643%7D&brand=phet&ea&fuzzBoard&supportsInteractiveDescription=true&memoryLimit=1000
Query: brand=phet&ea&fuzzBoard&supportsInteractiveDescription=true&memoryLimit=1000
Uncaught Error: Assertion failed: Attempted to attach to an already attached pointer
Error: Assertion failed: Attempted to attach to an already attached pointer
at window.assertions.assertFunction (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1664913638509/assert/js/assert.js:28:13)
at assert (Pointer.ts:285:14)
at attach (Pointer.ts:185:11)
at addInputListener (KeyboardDragListener.ts:271:22)
at apply (PhetioAction.ts:124:16)
at execute (KeyboardDragListener.ts:512:43)
at inputEvent (Input.ts:1804:91)
at dispatchToListeners (Input.ts:1841:11)
at dispatchToTargets (Input.ts:1759:9)
at dispatchEvent (Input.ts:1133:11)
id: Bayes Puppeteer
Snapshot from 10/4/2022, 2:00:38 PM
@pixelzoom
Copy link
Contributor Author

pixelzoom commented Oct 5, 2022

Reproduced locally in ph-scale and ph-scale-basic, by running from phetmarks with:

?brand=phet&ea&fuzzBoard&supportsInteractiveDescription=true&memoryLimit=1000

Unfortunately the stack trace is not more specific than what's shown above. I can't tell which of several KeyboardDragListeners is failing.

@pixelzoom
Copy link
Contributor Author

pixelzoom commented Oct 5, 2022

Running with ?brand=phet&ea&debugger&fuzzBoard&screens=1, I isolated this to the Macro screen. There are 2 KeyboardDragListener instances involved in that screen: 1 in MacroPHMeterNode, 1 in PHDropperNode. I tried commenting out one, then the other. Oddly, they both need to be included. So it seems that one of them is remaining attached to the pointer, and I'm unclear on how/why that can happen.

@pixelzoom
Copy link
Contributor Author

The KeyboardDragListeners are very straightforward.

MacroPHMeterNode.ts:

    this.addInputListener( new KeyboardDragListener( {
      dragVelocity: 300, // velocity of the Node being dragged, in view coordinates per second
      shiftDragVelocity: 20, // velocity with the Shift key pressed, typically slower than dragVelocity
      positionProperty: probe.positionProperty,
      dragBoundsProperty: dragBoundsProperty,
      transform: modelViewTransform,
      tandem: providedOptions.tandem.createTandem( 'keyboardDragListener' )
    } ) );

PHDropperNode.ts:

    this.addInputListener( new KeyboardDragListener( {
      dragVelocity: 300, // velocity of the Node being dragged, in view coordinates per second
      shiftDragVelocity: 20, // velocity with the Shift key pressed, typically slower than dragVelocity
      positionProperty: dropper.positionProperty,
      dragBoundsProperty: new Property( dropper.dragBounds ),
      transform: modelViewTransform,
      tandem: options.tandem.createTandem( 'keyboardDragListener' )
    } ) );

The failure occurs at line 271 in KeyboardDragListener.ts:

      // If there are no movement keys down, attach a listener to the Pointer that will tell the AnimatedPanZoomListener
      // to keep this Node in view
      if ( !this.movementKeysDown && KeyboardUtils.isMovementKey( event.domEvent ) ) {
        assert && assert( this._pointer === null, 'We should have cleared the Pointer reference by now.' );
        this._pointer = event.pointer as PDOMPointer;
271     event.pointer.addInputListener( this._pointerListener, true );
      }

event.pointer.addInputListener fails because event.pointer.isAttached() is true -- the pointer is already attached.

The comments indicate that this bit of code in KeyboardDragListener is related to pan/zoom, and git history identifies @jessegreenberg as the author. @jessegreenberg could you have a look please?

@jessegreenberg
Copy link
Contributor

jessegreenberg commented Oct 5, 2022

Sorry you ran into this, but this problem was fixed with phetsims/scenery#1461. I let the sim fuzz for 15 min with ?brand=phet&ea&debugger&fuzzBoard&screens=1 and never saw the problem. Then reverted the change there and hit it right away. @pixelzoom over to you to confirm and close. I can also see how that change would fix this issue too.

@jessegreenberg jessegreenberg removed their assignment Oct 5, 2022
@pixelzoom
Copy link
Contributor Author

Confirmed - CT is no longer reporting this problem, and I can no longer reproduce locally. Thanks for the quick fix! Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants