Skip to content

Can SoundGenerator's dispose call soundManager.removeSoundGenerator? #192

@zepumph

Description

@zepumph

@AgustinVallejo and I are finding discrepancies about how it is best to dispose SoundGenerators (while working on phetsims/scenery-phet#849). Looking at usages of soundManager.removeSoundGenerator, most are calling dispose on the soundGenerator right there (and the others seem like they likely should be).

We were brainstorming a couple of more automated ways of handling this.

  • Perhaps like calling removeSoundGenerator (with grace) from the disposal of SoundGenerator automatically.
  • Or having addSoundGenerator hook into the disposal of the soundGenerator to auto remove (then that listener is removed if removeSoundGenerator is called without disposing).

I'd start by looking at the 17 usages of removeSoundGenerator() to see if this is really the pattern we want to propagate across the project. Can't the library support this internally?

@jbphet if you give me some direction I'm happy to take a look at implementing.

For example for our new RichKeyboardDragListener:

https://github.com/phetsims/scenery-phet/blob/355d4de45aeeecea3d0537b80af0adcccc848060/js/RichKeyboardDragListener.ts#L88-L99

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions