particle-emitter icon indicating copy to clipboard operation
particle-emitter copied to clipboard

emitter.updateOwnerPos throws an error if emitter is destroyed

Open jordan-octavia-blue opened this issue 2 years ago • 2 comments

How to reproduce:

Make an emitter. emitter.destroy() emitter.updateOwnerPos(0,0)

It throws an error that can interrupt js execution.

Emitter.ts:491 Uncaught TypeError: Cannot set properties of null (setting 'x')
    at Emitter.updateOwnerPos (Emitter.ts:491:23)
    public updateOwnerPos(x: number, y: number): void
    {
        this._posChanged = true;
        this.ownerPos.x = x; // ERROR OCCURS HERE
        this.ownerPos.y = y;
    }

jordan-octavia-blue avatar Feb 08 '23 15:02 jordan-octavia-blue

Yes, it is intended that you don't use an emitter after destroying it. If you just wanted all your particles gone but to continue using the emitter, use Emitter.cleanup().

andrewstart avatar Feb 08 '23 16:02 andrewstart

Yes, but in the event that it is accidentally used after being destroyed - I would assume it would be better to fail silently or log an error than to throw and interrupt execution? A simple

if(this.owner){...}

would prevent it from throwing. This is easy to happen on accident if the emitter is in an array and wasn't removed from the array after being destroyed.

jordan-octavia-blue avatar Feb 08 '23 16:02 jordan-octavia-blue