Skip to content

Commit a8934c3

Browse files
committed
Phaser.Sound will now automatically check the Cache to see if the audio file it is using is still there or not. If not then it will automatically called Sound.destroy on itself. If you do not desire this result then you should ensure that you undertake all house-keeping yourself, and properly destroy Sound objects _before_ calling Cache.removeSound (phaserjs#1946)
1 parent 26e364a commit a8934c3

3 files changed

Lines changed: 11 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ If you are an exceptional JavaScript developer and would like to join the Phaser
257257
* Cache.getFrameByIndex has a new `cache` parameter (that defaults to the Image cache, but can be changed to any other)
258258
* Cache.getFrameByName has a new `cache` parameter (that defaults to the Image cache, but can be changed to any other)
259259
* Device.canPlayVideo now checks for `ogv` as a valid file extension for OGG video files (thanks @JB-Tellez #1928)
260+
* Phaser.Sound will now automatically check the Cache to see if the audio file it is using is still there or not. If not then it will automatically called `Sound.destroy` on itself. If you do not desire this result then you should ensure that you undertake all house-keeping yourself, and properly destroy Sound objects _before_ calling `Cache.removeSound` (#1946)
260261

261262

262263
### Bug Fixes

src/loader/Cache.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,6 +1708,10 @@ Phaser.Cache.prototype = {
17081708
/**
17091709
* Removes a sound from the cache.
17101710
*
1711+
* If any `Phaser.Sound` objects use the audio file in the cache that you remove with this method, they will
1712+
* _automatically_ destroy themselves. If you wish to have full control over when Sounds are destroyed then
1713+
* you must finish your house-keeping and destroy them all yourself first, before calling this method.
1714+
*
17111715
* Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere
17121716
* then it will persist in memory.
17131717
*

src/sound/Sound.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,12 @@ Phaser.Sound.prototype = {
404404
*/
405405
update: function () {
406406

407+
if (!this.game.cache.checkSoundKey(this.key))
408+
{
409+
this.destroy();
410+
return;
411+
}
412+
407413
if (this.isDecoded && !this._onDecodedEventDispatched)
408414
{
409415
this.onDecoded.dispatch(this);

0 commit comments

Comments
 (0)