P5js code crash

I just realized that due to this loop, the code is going to crash after playing 4 5 notes.
how can I avoid an infinitive loop here?

function granularPlay(){
  for(let i=1;i<10;i++){
    if (doorbell[i].contains(mouseX, mouseY)) {
  //var dure=map(abs(doorbell[i].center()-mouseX),0,50,0.001,5);
      randomStartPos = float(random(0.01, (song[i].duration())-0.001));
  		//playBackRate = map(abs(doorbell[i].center()-mouseX),0,50,1,1.1)
    song[i].loop(0.001,playBackRate,0.25,randomStartPos,0.01);
        reset(); 
      env.setInput(song[i]);
      env.play();
      reset();
    }
  }
}

function reset() {
  env = new p5.Envelope();
  env.setADSR(attackTime, decayTime, susPercent, releaseTime);
  env.setRange(attackLevel, releaseLevel);
}

https://editor.p5js.org/l3ehfar/sketches/JFf1Dxf2K

Why do you believe this is an infinite loop?

one of the commands, i could not identify up to now,
is causing a memory leak.
( see my remark here )
but i was able one time to stop the sketch in p5.js
but the cpu / memory usage stays high ( and some sound? ) until i was able to close the browser.

so, it might be that there is no way to do it with this library

also pls erase my reset idea, as it not helps.


but i do see a big problem in your FOR 9 loop
-a- now in your setup you do already the

env.setInput(song[i]);

so in case you want start that song you not need to do it again, only

env.play();

-b- but pls only one time.
you do that as long mouse over again and again.

-c- you can try a different way of reset,
not the envelope, stop the other songs

if ( mouseover && !song[i]isPlaying() )   song[i].play();
else                                      song[i].stop();

or better change to mouse click instead mouse over