-
-
Notifications
You must be signed in to change notification settings - Fork 682
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
prevent crashes during completion of callbacks on disposed SoundFiles #320
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -221,9 +221,11 @@ define(function (require) { | |
request.onload = function() { | ||
if (request.status === 200) { | ||
// on sucess loading file: | ||
if (!self.panner) return; | ||
ac.decodeAudioData(request.response, | ||
// success decoding buffer: | ||
function(buff) { | ||
if (!self.panner) return; | ||
self.buffer = buff; | ||
self.panner.inputChannels(buff.numberOfChannels); | ||
if (callback) { | ||
|
@@ -232,6 +234,7 @@ define(function (require) { | |
}, | ||
// error decoding buffer. "e" is undefined in Chrome 11/22/2015 | ||
function() { | ||
if (!self.panner) return; | ||
var err = new CustomError('decodeAudioData', errorTrace, self.url); | ||
var msg = 'AudioContext error at decodeAudioData for ' + self.url; | ||
if (errorCallback) { | ||
|
@@ -245,6 +248,7 @@ define(function (require) { | |
} | ||
// if request status != 200, it failed | ||
else { | ||
if (!self.panner) return; | ||
var err = new CustomError('loadSound', errorTrace, self.url); | ||
var msg = 'Unable to load ' + self.url + '. The request status was: ' + | ||
request.status + ' (' + request.statusText + ')'; | ||
|
@@ -276,7 +280,9 @@ define(function (require) { | |
else if (this.file !== undefined) { | ||
var reader = new FileReader(); | ||
reader.onload = function() { | ||
if (!self.panner) return; | ||
ac.decodeAudioData(reader.result, function(buff) { | ||
if (!self.panner) return; | ||
self.buffer = buff; | ||
self.panner.inputChannels(buff.numberOfChannels); | ||
if (callback) { | ||
|
@@ -285,6 +291,7 @@ define(function (require) { | |
}); | ||
}; | ||
reader.onerror = function(e) { | ||
if (!self.panner) return; | ||
if (onerror) { | ||
onerror(e); | ||
} | ||
|
@@ -1301,6 +1308,7 @@ define(function (require) { | |
|
||
// act on the result | ||
offlineContext.oncomplete = function(e) { | ||
if (!self.panner) return; | ||
var filteredBuffer = e.renderedBuffer; | ||
var bufferData = filteredBuffer.getChannelData(0); | ||
|
||
|
@@ -1652,9 +1660,10 @@ define(function (require) { | |
* <div><code> | ||
* var inp, button, mySound; | ||
* var fileName = 'cool'; | ||
* function setup() { | ||
* function preload() { | ||
* mySound = loadSound('assets/doorbell.mp3'); | ||
* | ||
* } | ||
* function setup() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 sorry for the trouble here! |
||
* btn = createButton('click to save file'); | ||
* btn.position(0, 0); | ||
* btn.mouseClicked(handleMouseClick); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does the trick, but I wonder if there's a better way to check if the soundfile has been disposed. Or, better yet, to cancel any incomplete callbacks when the soundfile is disposed.