mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-08-20 18:29:57 -04:00
Add VM.clear method
Use it before loading projects so targets don't accumulate when multiple projects are loaded on the same instance. Move check to see if the clone is the original clone onto the block implementation so all clones can be removed. Fixes #274
This commit is contained in:
parent
503de088fe
commit
bd95c1461d
4 changed files with 28 additions and 12 deletions
src/engine
|
@ -368,18 +368,26 @@ Runtime.prototype.startHats = function (requestedHatOpcode,
|
|||
return newThreads;
|
||||
};
|
||||
|
||||
/**
|
||||
* Dispose all targets. Return to clean state.
|
||||
*/
|
||||
Runtime.prototype.dispose = function () {
|
||||
this.stopAll();
|
||||
this.targets.map(this.disposeTarget, this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Dispose of a target.
|
||||
* @param {!Target} target Target to dispose of.
|
||||
*/
|
||||
Runtime.prototype.disposeTarget = function (target) {
|
||||
// Allow target to do dispose actions.
|
||||
target.dispose();
|
||||
// Remove from list of targets.
|
||||
var index = this.targets.indexOf(target);
|
||||
if (index > -1) {
|
||||
this.targets.splice(index, 1);
|
||||
}
|
||||
Runtime.prototype.disposeTarget = function (disposingTarget) {
|
||||
this.targets = this.targets.filter(function (target) {
|
||||
if (disposingTarget !== target) return true;
|
||||
// Allow target to do dispose actions.
|
||||
target.dispose();
|
||||
// Remove from list of targets.
|
||||
return false;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue