Stopping a non streaming sound just before disposing it throws in Safari

This might not be very urgent as you can just, don’t stop the sound before disposing it, but thought it was good to report never the less.

The exception that you get is InvalidStateError: The object is in an invalid state and here is a playground with the repro link. This exception is thrown (only in Safari) if you call stop() twice on an AudioBufferSourceNode. The reason why this might be called twice is because the property this.isPlaying is updated asynchronously after the first stop, and a dispose will try to stop the sound again.

I don’t think this is urgent and feel free to close it but I just wanted to point this out as Safari is not the most common browser and this might lead to other types of bugs if you are not expecting a throw when disposing a sound.

You’re right, here’s a PR that should fix the problem:


Great, thanks for the quick fix!

there is still an error like this when calling stop and then dispose in Safari. It occurs only on some devices/os versions I think and I don’t have any of those, so it’s hard for me to reproduce.

It could also be that the same error regressed. The thing I’m most worried about is that a crash in the dispose()->stop() code prevents the rest of the actual disposing, leading to memory leaks.

I do not seem to be able to repro :frowning: would be amazing if we were having a repro for this ?

I think it should be the same repro as OP.
The error is “stop@[native code]”.

The crashed iOS UserAgents all have “OS 14_3 like Mac OS X” or “OS 14_4 like Mac OS X”.
14_6 and higher don’t crash.
For Mac I got crashed Version/14.0.2 and Version/14.0.3 and not crashed 14.1.2+

I guess I should find such a device :slight_smile:

Let s see if @Cedric can repro ?

Check the PR mentioned above with iOS 15.0.2 and got no throw.

No throw on Mac OS 11.6 with Safari 15.0


Hi @mise just checking in, were you able to find a repro? :slight_smile:

Hi Carol, I’m pretty sure it’s a matter of finding the right iOS / Safari versions, but I haven’t found them.

1 Like