1
0
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:
Alain Pitiot 2020-07-31 16:13:21 +02:00 committed by GitHub
commit 394311e650
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 0 deletions

View File

@ -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.
*

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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,