I used debug tools, found out that something doesn't work when I try to insert a point into the node which already contains a point, and they both should go to the same subnode. For instance,
particles[1] = particle([0.1, 0.1, 0.1], 1.0, [0.0,0.0,0.0], [0.0,0.0,0.0]) tree = InsertParticle(1,1,tree,particles) particles[2] = particle([0.13, 0.2, 0.15], 1.0, [0.0,0.0,0.0], [0.0,0.0,0.0 ]) tree = InsertParticle(2,1,tree,particles) leads to infinite loop. However, I cannot see the reason.