Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unloading an unloaded howl causes a different howl to play silently #1103

Closed
mtsanford opened this issue Dec 19, 2018 · 2 comments
Closed

Unloading an unloaded howl causes a different howl to play silently #1103

mtsanford opened this issue Dec 19, 2018 · 2 comments

Comments

@mtsanford
Copy link

mtsanford commented Dec 19, 2018

Steps:

  1. 2 howls with preload = false, same src
  2. howl1.load()
  3. after a delay, howl2.unload()
  4. howl1.play()

howl2 plays, but it is silent

https://codepen.io/marktsanford/pen/GPrpgv

Note: this did not happen in 2.0.12, but does in all subsequent releases.

@mtsanford
Copy link
Author

mtsanford commented Dec 20, 2018

I see what's going on. Line 1728.

      // Delete this sound from the cache (if no other Howl is using it).
      var remCache = true;
      for (i=0; i<Howler._howls.length; i++) {
        if (Howler._howls[i]._src === self._src) {
          remCache = false;
          break;
        }
      }

      if (cache && remCache) {
        delete cache[self._src];
      }

The unload function does not check to see if the howl is loaded. If it's not, the _src property is still an array and this check will fail:

if (Howler._howls[i]._src === self._src)

And this will delete from the cache.

// counterintuitively, cache['somestring'] === cache[['somestring']]
// so deleting with the _src array as index works when the array only has one string
delete cache[self._src];

Howl unload function needs to handle the case where the howl has never been loaded, to avoid erroneous removal from the cache.

I can make pull request if you like, but I'm not sure what the best way to handle this is.

@mtsanford
Copy link
Author

mtsanford commented Dec 20, 2018

Workaround is to make sure the howl is not unloaded before unloading it.

if (howl.state() != 'unloaded') howl.unload()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant