ibesora / Leaflet.Quadtree

A quadtree to use with Leaflet.js
Other
25 stars 3 forks source link

Infinite loop at add #4

Open vutle opened 3 years ago

vutle commented 3 years ago

I tried to add 100k markers and it seems the library is running in an infinite loop, it adds items forever.
More than 8 million objects... and still going before I stop the browser as it hang. I have to kill it.

I'm using the latest leaflet.

for(var i = 0; i < latlngs.length; ++i) {

  var circle = L.circle(latlngs[i], radius, cStyle2);
  circle.addTo(map);
   quadtree.add(circle);

}

ibesora commented 3 years ago

I've created a demo adding 1 million circles here (the tab might report as not responding, just need to wait for it to finish) but I can't reproduce what you are seeing. Can you provide the whole code to reproduce it?

vutle commented 3 years ago

Interesting:

When I run the below code to create approximately 100k circles, after loading for sometimes, Chrome and Edge browser warn of an out of the memory. for(var i = 0; i < latlngs.length; ++i) { var circle = L.circle(latlngs[i], radius); quadtree.add(circle); }

The colliders inside Quadtree.js file grows to > 35 million objects at this loop.

//Append our own elements and if we have children, theirs colliders = colliders.concat(self.elements); for(var i=0, len=self.nodes.length; i<len; ++i) { colliders = colliders.concat(self.nodes[i].getPossibleColliders(bounds)); }

also number of element at line 123 grows without stopping: self.elements.push(elem);

After sometimes I get this error below:

Uncaught RangeError: Invalid array length at Array.concat () at i.getPossibleColliders (Leaflet.Quadtree.js:289) at i.getPossibleColliders (Leaflet.Quadtree.js:289) at i.getPossibleColliders (Leaflet.Quadtree.js:289) at i.getColliders (Leaflet.Quadtree.js:310) at i.updateChildNodesElements (Leaflet.Quadtree.js:185) at i.add (Leaflet.Quadtree.js:104) at Object.success (dashboard:928) at c (jquery.min.js:2) at Object.fireWith [as resolveWith] (jquery.min.js:2)

On Mon, Jun 28, 2021 at 3:55 AM Isaac Besora Vilardaga < @.***> wrote:

I've created a demo adding 1 million circles here https://ibesora.github.io/Leaflet.Quadtree/demos/1M/demo.html (the tab might report as hang but you just need to wait for it to finish) but I can't reproduce what you are seeing. Can you provide the whole code to reproduce it?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ibesora/Leaflet.Quadtree/issues/4#issuecomment-869202339, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABPT5CFFBI7HILGHTUALWITTU5QZXANCNFSM47LCY5GQ .