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
[Bug]: ng-tsparticles load engine with [particlesInit] gets called everytime #4151
Comments
It's definitely a bug, thanks for reporting that |
Yeah probably, I went a bit through the source code and also created as promised a tiny example: https://stackblitz.com/edit/ng-particles-load-engine-bug?file=src/app/app.component.ts If you click the visible button, you notice that there appears a dolphin (but it shouldn't) and it also freezes / stutters a bit (I assume due to loading the engine multiple times) If you enable the flag The issue with movers filling is another bug. It must be related in the way the container is created and handled In I assume the container reference changes, etc. because after debugging it, it will always set a new entry in the map. https://github.com/matteobruni/tsparticles/blob/main/engine/src/Core/Utils/Plugins.ts#L92 getMovers(container: Container, force = false): IParticleMover[] {
let res = this.movers.get(container);
if (!res || force) {
res = [...this.moversInitializers.values()].map((t) => t(container));
this.movers.set(container, res); // <<<---- container is always a different reference and will constantly set because it won't be found or through force flag
}
return res;
} Easy solution would be to use a key string (the id), idk if that would break the backwards compatibility though ;) |
Contact Details
a.diller@dolphbit.de
What happened?
Just started today with this awesome library and after some struggling and digging through the documentation I eventually found an issue or I misunderstood something.
The following use case: I have two
<ng-particles [particlesInit]="init">
components placed on a page.The init function is the following and does partial loading of what I need.
So this functions gets called two times and it works.
But one
<ng-particles [particlesInit]="init" *ngIf="condition">
has angIf
which is used to toggle visibility (not always needed).Whenever I toggle it, the
init
function gets executed.This will fill the
engine.plugins.movers
map for example with many entries of the same id.My bugfix to check if the domArray has already the id will fix this issue.
I just noticed it by accident, because whenever I toggle and
loadABC(engine)
the otherng-particles
does emit for some and places an particle on the canvas. (the particle count is 0 when I check it, but I would need to callcontainer.canvas.clear();
to remove it) After further investigation it seems to be in relation with the multiple loading.Am I misunderstanding something or is this a bug?
If the issue is still not clear, let me know. I try to create an example project.
I know documentation is probably the last thing, but it took me while to figure out everything I want. Docs are a little bit messy.
Eventually I find some time to contribute where I can. ❤️
tsParticles Version
2.0.6
Which library are you using?
Angular (ng-particles)
tsParticles Configuration
What browsers are you seeing the problem on?
Chrome
Relevant log output
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: