1
0
mirror of https://github.com/psychopy/psychojs.git synced 2025-05-11 16:18:10 +00:00

visual/Image/Text/Movie/Shape: call destroy on internal pixi instance before updating across stimulus classes

This commit is contained in:
Sotiri Bakagiannis 2020-07-24 17:00:37 +01:00
parent 08972dae90
commit e0b7bc8d5b
4 changed files with 27 additions and 0 deletions

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,