mirror of
https://github.com/psychopy/psychojs.git
synced 2025-05-11 16:18:10 +00:00
Merge pull request #112 from thewhodidthis/nf#111--release
core/MinimalStim: add release method
This commit is contained in:
commit
394311e650
@ -160,6 +160,26 @@ export class MinimalStim extends PsychObject
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Release the PIXI representation, if there is one.
|
||||
*
|
||||
* @name module:core.MinimalStim#release
|
||||
* @function
|
||||
* @public
|
||||
*/
|
||||
release()
|
||||
{
|
||||
this._setAttribute('autoDraw', false, log);
|
||||
this.status = PsychoJS.Status.STOPPED;
|
||||
|
||||
if (typeof this._pixi !== 'undefined')
|
||||
{
|
||||
this._pixi.destroy(true);
|
||||
this._pixi = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the stimulus, if necessary.
|
||||
*
|
||||
|
@ -268,6 +268,14 @@ export class ImageStim extends util.mix(VisualStim).with(ColorMixin)
|
||||
}
|
||||
this._needUpdate = false;
|
||||
|
||||
// Guard against memory leaks
|
||||
// https://discourse.psychopy.org/t/psychojs-platform-version-2020-1-memory-leak-in-visual-stimulus-setters/14571
|
||||
// https://www.html5gamedevs.com/topic/1189-pixi-how-to-destroy-cleanup/
|
||||
if (typeof this._pixi !== 'undefined')
|
||||
{
|
||||
this._pixi.destroy(true);
|
||||
}
|
||||
|
||||
this._pixi = undefined;
|
||||
|
||||
// no image to draw: return immediately
|
||||
|
@ -334,6 +334,12 @@ export class MovieStim extends VisualStim
|
||||
}
|
||||
this._needUpdate = false;
|
||||
|
||||
// Guard against memory leaks
|
||||
if (typeof this._pixi !== 'undefined')
|
||||
{
|
||||
this._pixi.destroy(true);
|
||||
}
|
||||
|
||||
this._pixi = undefined;
|
||||
|
||||
// no movie to draw: return immediately
|
||||
|
@ -252,6 +252,12 @@ export class ShapeStim extends util.mix(VisualStim).with(ColorMixin)
|
||||
|
||||
this._getPolygon(/*true*/); // this also updates _vertices_px
|
||||
|
||||
// Guard against memory leaks
|
||||
if (typeof this._pixi !== 'undefined')
|
||||
{
|
||||
this._pixi.destroy(true);
|
||||
}
|
||||
|
||||
this._pixi = undefined;
|
||||
|
||||
// no polygon to draw: return immediately
|
||||
|
@ -297,6 +297,13 @@ export class TextStim extends util.mix(VisualStim).with(ColorMixin)
|
||||
(this._bold ? 'bold ' : '') +
|
||||
(this._italic ? 'italic ' : '') +
|
||||
fontSize + 'px ' + this._font;
|
||||
|
||||
// Guard against memory leaks
|
||||
if (typeof this._pixi !== 'undefined')
|
||||
{
|
||||
this._pixi.destroy(true);
|
||||
}
|
||||
|
||||
this._pixi = new PIXI.Text(this._text, {
|
||||
font: font,
|
||||
fill: color.hex,
|
||||
|
Loading…
Reference in New Issue
Block a user