Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

emitter.updateOwnerPos throws an error if emitter is destroyed #194

Open
jdoleary opened this issue Feb 8, 2023 · 2 comments
Open

emitter.updateOwnerPos throws an error if emitter is destroyed #194

jdoleary opened this issue Feb 8, 2023 · 2 comments

Comments

@jdoleary
Copy link

jdoleary commented Feb 8, 2023

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;
    }
@andrewstart
Copy link
Contributor

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().

@jdoleary
Copy link
Author

jdoleary commented Feb 8, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants