Closed pixelzoom closed 4 years ago
A similar failure occurs in the "Two Dimensions" screen.
Fixed, ready for review. Lesson is: don't unlink something that's not a listener.
For some reason, before 8751534, even when though we tried to unlink something that was not a listener, the listener that we meant to unlink was unlinked after the (incorrect) call to unlink and the arrows were correctly hidden. After that commit, as we were always trying to unlink something that was not a listener, unlink was not called at all and even after holding and releasing a mass, the arrows kept showing up.
The real problem was that the callback
variable was being created inside the function that was linking and unlinking the listener, so we were using different functions to link and unlink, while the reason to the line const callback = this.overUpCallback.bind( this );
to exist was exactly to be able to link callback
to dragListener.isOverProperty
and later use the same callback
to unlink. Moving the line out of the function yields the expected behaviour.
Thanks for explaining the problem with context of the callback
variable, that makes sense and I hadn't noticed. I do think it's still worth checking hasListener
before calling unlink
. arrowsVisibilityProperty
currently has an initial value of false
. But if arrowsVisibilityProperty
had an initial value of false
, then unlink
would be called before link
, and would trigger the "tried to removeListener on something that wasn't a listener" assertion.
Yes, that makes sense. The check is still there, and I'll remember to call hasListener
before calling unlink
the next time.
Related to #2 (code review).
?ea
This assertion failure occurs: