title: XNA DrawPrimitives unintended line to 0,0
body: <p>I'm trying to learn XNA.
  I'm currently drawing a figure on the screen where the user clicks.
  I use an indexbuffer and PrimitiveType.LineList.
  It works fine, however occasionally a line is drawn between a figure's first vertex and what seems like position 0,0. Why is it doing that?</p>
  
  <p><strong>Screenshot</strong>
  <a href="https://i.stack.imgur.com/HSCXF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HSCXF.png" alt="enter image description here"></a></p>
  
  <p><strong>Draw Code</strong></p>
  
  <pre><code>    protected override void Draw(GameTime gameTime)
      {
          GraphicsDevice.Clear(Microsoft.Xna.Framework.Color.CornflowerBlue);
  
          #region Transform //Covered later in the Course
          effect.VertexColorEnabled = true;
          effect.World = Matrix.Identity;
          effect.View = new Matrix(
              1.0f, 0.0f, 0.0f, 0.0f,
              0.0f, 1.0f, 0.0f, 0.0f,
              0.0f, 0.0f, -1.0f, 0.0f,
              0.0f, 0.0f, 0.0f, 1.0f
          );
          effect.Projection = Matrix.CreateOrthographicOffCenter(
                0f, this.GraphicsDevice.DisplayMode.Width,
                this.GraphicsDevice.DisplayMode.Height, 0f,
              -10f, 10f
          );
          #endregion -&gt; Wordt later behandeld
          if (vertex.Count &gt; 0)
          {
              VertexBuffer vBuffer = new VertexBuffer(this.GraphicsDevice, typeof(VertexPositionColor), vertex.Count, BufferUsage.None);
              vBuffer.SetData&lt;VertexPositionColor&gt;(vertex.ToArray());
  
              this.GraphicsDevice.SetVertexBuffer(vBuffer);
  
  
              effect.CurrentTechnique.Passes[0].Apply();
  
              this.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.LineList, 0, 0, this.vertex.Count, 0, vertex.Count * 2);
          }
  
          base.Draw(gameTime);
      }
  </code></pre>
  
  <p><strong>Add Figure Code</strong></p>
  
  <pre><code>    private void addFigure(Microsoft.Xna.Framework.Point location, Size size, Microsoft.Xna.Framework.Color color)
      {
          this.vertex.Add(new VertexPositionColor(new Vector3(location.X, location.Y - 40, 0), Microsoft.Xna.Framework.Color.Red));
  
          this.vertex.Add(new VertexPositionColor(new Vector3(location.X + 10, location.Y - 20, 0), Microsoft.Xna.Framework.Color.Red));
  
          this.vertex.Add(new VertexPositionColor(new Vector3(location.X + 20, location.Y - 20, 0), Microsoft.Xna.Framework.Color.Red));
          this.vertex.Add(new VertexPositionColor(new Vector3(location.X + 20, location.Y - 10, 0), Microsoft.Xna.Framework.Color.Red));
  
          this.vertex.Add(new VertexPositionColor(new Vector3(location.X + 40, location.Y, 0), Microsoft.Xna.Framework.Color.Red));
          this.vertex.Add(new VertexPositionColor(new Vector3(location.X + 20, location.Y + 10, 0), Microsoft.Xna.Framework.Color.Red));
  
          this.vertex.Add(new VertexPositionColor(new Vector3(location.X + 20, location.Y + 20, 0), Microsoft.Xna.Framework.Color.Red));
          this.vertex.Add(new VertexPositionColor(new Vector3(location.X + 10, location.Y + 20, 0), Microsoft.Xna.Framework.Color.Red));
  
          this.vertex.Add(new VertexPositionColor(new Vector3(location.X, location.Y + 40, 0), Microsoft.Xna.Framework.Color.Red));
          this.vertex.Add(new VertexPositionColor(new Vector3(location.X - 10, location.Y + 20, 0), Microsoft.Xna.Framework.Color.Red));
  
          this.vertex.Add(new VertexPositionColor(new Vector3(location.X - 20, location.Y + 20, 0), Microsoft.Xna.Framework.Color.Red));
          this.vertex.Add(new VertexPositionColor(new Vector3(location.X - 20, location.Y + 10, 0), Microsoft.Xna.Framework.Color.Red));
  
          this.vertex.Add(new VertexPositionColor(new Vector3(location.X - 40, location.Y, 0), Microsoft.Xna.Framework.Color.Red));
          this.vertex.Add(new VertexPositionColor(new Vector3(location.X - 20, location.Y - 10, 0), Microsoft.Xna.Framework.Color.Red));
  
          this.vertex.Add(new VertexPositionColor(new Vector3(location.X - 20, location.Y - 20, 0), Microsoft.Xna.Framework.Color.Red));
          this.vertex.Add(new VertexPositionColor(new Vector3(location.X - 10, location.Y - 20, 0), Microsoft.Xna.Framework.Color.Red));
  
          for (short i = 16; i &gt; 0; i--)
          {
              this.index.Add((short)(this.vertex.Count - i));
              if (i - 1 &gt; 0)
              {
                  this.index.Add((short)(this.vertex.Count - i + 1));
              }
              else
              {
                  this.index.Add((short)(this.vertex.Count - 16));
              }
          }
  
          this.ib = new IndexBuffer(this.GraphicsDevice, typeof(short), this.index.Count, BufferUsage.None);
          this.ib.SetData&lt;short&gt;(this.index.ToArray());
          this.GraphicsDevice.Indices = ib;
      }
  </code></pre>