Commit 9ff6e8a
authored
Audio: clean up event listeners and buffer view on destroy (#75)
The Audio constructor binds three window-level event listeners
(keydown / click / touchend) to drive startPlayback. They're only
removed when startPlayback() fires; if the Emulator is destroyed
before the user produces a gesture — or if an embedder recreates
the Emulator multiple times before that happens — the listeners
stayed attached to a stale Audio instance forever.
Audio also holds a TypedArray view (this.buffer) into the wasm
heap region returned by _get_audio_buffer_ptr. After Emulator
destroy() calls _emulator_delete + _free, that backing memory is
gone, and any held reference to the buffer view points at freed
memory.
Add Audio.destroy(): removes the gesture listeners and nulls out
the buffer view. Call it from Emulator.destroy() before
_emulator_delete so the cleanup happens while the wasm pointer is
still valid.1 parent e3caa27 commit 9ff6e8a
1 file changed
Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
| 197 | + | |
197 | 198 | | |
198 | 199 | | |
199 | 200 | | |
| |||
658 | 659 | | |
659 | 660 | | |
660 | 661 | | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
661 | 673 | | |
662 | 674 | | |
663 | 675 | | |
| |||
0 commit comments