phetsims / fourier-making-waves

"Fourier: Making Waves" is an educational simulation in HTML5, by PhET Interactive Simulations.
GNU General Public License v3.0
6 stars 3 forks source link

State wrapper error in AmplitudeKeypadDialog #220

Open pixelzoom opened 2 years ago

pixelzoom commented 2 years ago

When fuzz testing the State wrapper with phet-io-wrappers/state/?sim=fourier-making-waves&phetioDebug&fuzz, this error occurs:

AmplitudeKeypadDialog.js? [sm]:202 Uncaught TypeError: this.closeCallback is not a function
    at AmplitudeKeypadDialog.hide (AmplitudeKeypadDialog.js? [sm]:202:10)
    at fire (BarrierRectangle.js? [sm]:47:57)
    at TinyEmitter.emit (TinyEmitter.ts:93:9)
    at Emitter.emit (Emitter.ts:65:22)
    at FireListener.fire (FireListener.ts:100:23)
    at FireListener.ts:148:14
    at FireListener.onRelease (PressListener.ts:750:17)
    at PhetioAction.execute (PhetioAction.ts:123:17)
    at FireListener.release (PressListener.ts:508:25)
    at FireListener.release (FireListener.ts:141:11)

AmplitudeKeypadDialog is this dialog, opened by pressing on one of the amplitude values shown above the amplitude sliders.

screenshot_1642

AmplitudeKeypadDialog has field this.closeCallback. It's set when show is called, then called (and cleared) when hide is called. So what I guess is happening is that the dialog is somehow being opened by the State wrapper without calling show.

AmplitudeKeypadDialog has another field, this.enterCallback, that I suspect would have a similar problem. It's set when show is called, then called (and cleared) when the Enter button is pressed.

pixelzoom commented 2 years ago

A few things...

  show( order, enterCallback, closeCallback ) {
    // ... do stuff specific to AmplitudeKeypadDialog
    super.show();
  }
pixelzoom commented 2 years ago

It would be easier to avoid this problem by creating one AmplitudeKeypadDialog instance per amplitude.

I investigated this approach, and it looks promising. But it was not entirely straightforward, and I ran into problems with emphasized harmonics not behaving properly, followed by a crash. So I bailed for now, and will defer until we resume work on this sim.

pixelzoom commented 2 months ago

When this sim was converted to TypeScript in https://github.com/phetsims/fourier-making-waves/commit/600727cafa89370ef97ef8a664e033aeaa1aaaa3, the following change was made:

  public override hide(): void {
    super.hide();

    this.interruptSubtreeInput();
-   this.closeCallback();
+   this.closeCallback && this.closeCallback();

This fixed the crash during fuzzing. But the list of emphasized harmonics (managed via enterCallback and closeCallback) is not getting updated because state is just setting isShowingProperty.

So I'll leave this issue open, to be investigated when work resumes on a PhET-iO version of this sim.