title: Exception: Concurrent modification during iteration: Instance(length:17) of '_GrowableList'
body: <p>I make game. In //ERROR ZONE is called Exception. I don't understand it. Class game has List recrangles. </p>
  
  
  
  <pre class="lang-dart prettyprint-override"><code>void spawnt(){
  var rnd = new Random();
  var rnd2 = new Random();
  rnd = rnd.nextInt(100);
  if(rnd2.nextBool())
    rnd2 = rnd2.nextInt(100);
  else
    rnd2 = -rnd2.nextInt(100);
  var x = flappy.position["x"]+lastx+sw+rnd;
  var y = rnd2*pomer-100-1800*pomer-168*pomer;
  Rectangle vrch = new Rectangle("img/tube1.png", sw, sh, {"x":x, "y":y, "z":0});
  Rectangle spodek = new Rectangle("img/tube2.png", sw, sh, {"x":x, "y":sh+mezeray*pomer+y, "z":0});
  
  vrch.onCollision((_){
    checkover();
  });
  
  spodek.onCollision((_){
    checkover();
  });
  game.addObject(spodek);
  game.addObject(vrch);
  var cp = new Checkpoint(sw, mezeray, {"x":x+sw, "y":y+sh, "z":0});
  cp.onCollision((e){
    scoore++;
    querySelector("#scoore").text="SCOORE: ${scoore}";
    sounds[1].play();
    //THIS IS ERROR ZONE
    spawnt();
  });
  game.addObject(cp);
  
  rnd = new Random();
  rnd = rnd.nextInt(300);
  rnd2 = new Random();
  rnd2 = rnd2.nextInt(300);
  var rnd3 = new Random();
  rnd3 = new Random();
  rnd3 = rnd3.nextInt(10);
  Grab w;
  if(rnd3 == 0 || rnd3 == 1 || rnd3 == 2){
    w = new Grab("img/cigarette.png", 600*pomer, 418*pomer, {"x":x+sw+rnd,"y":sh+mezeray*pomer+y-mezeray*pomer+rnd2-168*pomer, "z":0});
    w.scale(0.2);
    w.onCollision((c){
      smokescreen = true;
      smoketimer.cancel();
      smoketimer = new Timer(const Duration(milliseconds: 10000), (){
        smokescreen = false;
      });
      kucky.play();
      if(csong)
        cig.play();
      csong = false;
    });
    game.addObject(w);
  }
  else if(rnd3 == 3 || rnd3 == 4){
    w = new Grab("img/whiskey.png", 162*pomer, 398*pomer, {"x":x+sw+rnd,"y":sh+mezeray*pomer+y-mezeray*pomer+rnd2-168*pomer, "z":0});
    w.scale(0.2);
    w.onCollision((c){
      AudioElement pr = new AudioElement("sounds/yes.${koncovka}");
      pr.play();
      whiskey++;
      if(whiskey&gt;=10 &amp;&amp; whiskey&lt;20){
        speedotoceni = 30;
        zhoupni();
      }
      else if(whiskey&gt;=20 &amp;&amp; whiskey&lt;30){
        speedotoceni = 25;
        zhoupni();
      }
      else if(whiskey&gt;=30 &amp;&amp; whiskey&lt;40){
        speedotoceni = 20;
        zhoupni();
      }
      else if(whiskey&gt;=40 &amp;&amp; whiskey&lt;50){
        speedotoceni = 15;
        zhoupni();
      }
      else if(whiskey&gt;=50 &amp;&amp; whiskey&lt;60){
       speedotoceni = 10;
        zhoupni();
      }
      else if(whiskey&gt;=60 &amp;&amp; whiskey&lt;70){
        speedotoceni = 5;
        zhoupni();
      }
      else if(whiskey&gt;=70 &amp;&amp; whiskey&lt;80){
        speedotoceni = 1;
        zhoupni();
      }
      querySelector("#scoore").text="SCOORE: ${scoore}";
    });
    game.addObject(w);
  }
  else if(rnd3 == 9){
    w = new Grab("img/jatra.png", 539*pomer, 521*pomer, {"x":x+sw+rnd,"y":sh+mezeray*pomer+y-mezeray*pomer+rnd2-168*pomer, "z":0});
    w.scale(0.1);
    w.onCollision((c){
      AudioElement pr = new AudioElement("sounds/yes.${koncovka}");
      pr.play();
      jatra++;
      document.cookie = "jatra=${jatra}; expires=Thu, 24 Dec 4000 00:00:00 GMT; path=/";
      querySelector("#jatracount").text = jatra.toString();
    });
    game.addObject(w);
   }
  lastx = lastx+300*pomer+rnd;
  }
  </code></pre>
  
  <p>class Game.dart</p>
  
  <pre class="lang-dart prettyprint-override"><code>  import 'dart:html';
    import 'dart:math';
    import 'dart:async';
    import 'Entity.dart';
    import 'Gravity.dart';
    import 'Rectangle.dart';
    import 'Camera.dart';
    import 'Checkpoint.dart';
  
    class Game {
      CanvasElement canvas;
      Gravity gravity;
      List&lt;Entity&gt; entities = new List();
      List&lt;Rectangle&gt; rectangles = new List();
      Camera camera;
      var leftSpace = 0;
      var topSpace = 0;
      var _onCollision;
      var _over = (_){};
      var _render = (_){};
      num _lastFrame = 0;
      bool isOver = false;
  
  
  Game(this.canvas, this.gravity){
    window.animationFrame.then((e){this.render(e);});
  }
  
  void addEntity(Entity entita){
    this.entities.add(entita);
  }
  
  void addObject(Rectangle rectangle){
    this.rectangles.add(rectangle);
  }
  
  void render(num delta){
    num fps = 1000/(delta-this._lastFrame);
    this._lastFrame = delta;
    CanvasRenderingContext2D ctx = this.canvas.context2D;
    ctx.clearRect(0, 0, this.canvas.width+this.leftSpace.abs(), this.canvas.height+this.topSpace.abs());
    this._render(true);
    this.rectangles.forEach((s){
      ctx.fillStyle=s.color;
      if(s.hasColor()){
        ctx.fillStyle=s.color;
        ctx.fillRect(s.position["x"]-this.leftSpace,s.position["y"]-this.topSpace,s.width,s.height);
      }
      else{
        ctx.drawImageScaled(s.texture, s.position["x"]-this.leftSpace,s.position["y"]-this.topSpace,s.width,s.height);
      }
    });
    this.entities.forEach((e){
      e.move(fps);
      e.power["y"] += this.gravity.operate(e)*(60/fps);
      ctx.save(); 
      ctx.translate(e.position["x"]-this.leftSpace+e.width/2, e.position["y"]-this.topSpace+e.height/2);
      ctx.rotate(e.rotation* PI/180);
      ctx.drawImageScaled(e.img, -(e.width/2), -(e.height/2), e.width, e.height);
      ctx.restore(); 
    });
    collisionResponse();
    checkCollisions();
    if(!this.camera.fixed["x"])
      this.leftSpace = this.camera.target.position["x"]-this.canvas.width/2+this.camera.target.width/2;
    else
      this.leftSpace = this.camera.fixedPos["x"];
  
    if(!this.camera.fixed["y"])
      this.topSpace = this.camera.target.position["y"]-this.canvas.height/2+this.camera.target.height/2;
    else
      this.topSpace = this.camera.fixedPos["y"];
    this._render(false);
    ctx.closePath();
    window.animationFrame.then((e){this.render(e);});
  }
  
  void onCollision(e){
    this._onCollision = e;
  }
  
  void collisionResponse(){
    this.rectangles.forEach((s){
      num x1 = s.position["x"];
      num y1 = s.position["y"];
      num z1 = s.position["z"];
      num w1 = s.width;
      num h1 = s.height;
  
      this.entities.forEach((e){
        num rot = e.rotation * (PI / 180);
        num x2 = e.position["x"];
        num y2 = e.position["y"];
        num z2 = e.position["z"];
        num w2 = e.width;
        num h2 = e.height;
        if(x2&gt;=x1-w2 &amp;&amp; x2&lt;=x1+w1 &amp;&amp; y2&gt;y1-h2 &amp;&amp; y2&lt;y1+h1 &amp;&amp; z1==z2){
          s.collisionResponse(e);
          e.collision(s);
          s.collision(e);
        }
      });
    });
  }
  
  void checkCollisions(){
    List&lt;Entity&gt; kolize = new List();
    for(Entity e1 in this.entities){
      num x1 = e1.position["x"];
      num y1 = e1.position["y"];
      num z1 = e1.position["z"];
      num w1 = e1.width;
      num h1 = e1.height;
  
      for(Entity e2 in this.entities){
        if(e1 == e2 || (kolize.indexOf(e1) != -1 &amp;&amp; kolize.indexOf(e2) != -1)) continue;
        num x2 = e2.position["x"];
        num y2 = e2.position["y"];
        num z2 = e2.position["z"];
        num w2 = e2.width;
        num h2 = e2.height;
        if(x2&gt;=x1-w2 &amp;&amp; x2&lt;=x1+w1 &amp;&amp; y2&gt;y1-h2 &amp;&amp; y2&lt;y1+h1 &amp;&amp; z1==z2){
          kolize.add(e1);
          kolize.add(e2);
        }
      }
    }
  }
  
  void over(){
    if(!this.isOver)
      this._over();
    this.isOver = true;
  }
  
  void onOver(e){
    this._over = e;
  }
  
  void onRender(f){
    this._render = f;
  }
  }
  </code></pre>
  
  <p>Uncaught Error: Concurrent modification during iteration: Instance(length:17) of '_GrowableList'.
  Stack Trace: 
  #0      List.forEach (dart:core-patch/growable_array.dart:241)</p>
  
  <p>#1      Game.collisionResponse (FlappyBird/web/classes/Game.dart:83:28)</p>
  
  <p>#2      Game.render (FlappyBird/web/classes/Game.dart:62:22)</p>
  
  <p>#3      Game.render. (FlappyBird/web/classes/Game.dart:75:47)</p>
  
  <p>#4      _rootRunUnary (dart:async/zone.dart:717)</p>
  
  <p>#5      _RootZone.runUnary (dart:async/zone.dart:854)</p>
  
  <p>#6      _Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:439)</p>
  
  <p>#7      _Future._propagateToListeners (dart:async/future_impl.dart:522)</p>
  
  <p>#8      _Future._complete (dart:async/future_impl.dart:303)</p>
  
  <p>#9      _SyncCompleter.complete (dart:async/future_impl.dart:44)</p>
  
  <p>#10     Window.animationFrame. (file:///E:/b/build/slave/dartium-win-full-stable/build/src/build/Release/obj/global_intermediate/blink/bindings/dart/dart/html/Window.dart:62)</p>
  
  <p>Exception: Concurrent modification during iteration: Instance(length:17) of '_GrowableList'.
    undefined (undefined:0:0)</p>
  
  <p>Is it enough?
  Does somebody know how to repair it?
  Thanks for answer. :)</p>