title: Bugs in Release not in Debug
body: <p>I'm building a top-down view demo for a path planning/collision avoidance method. c++ in Visual Studio 2010.</p>
  
  <p>When I run in Debug mode everything is fine. But when I run in Release, crazy behavior occurs. Previously my characters would speed up immensily and change direction when running into other characters, and now they are just dissapearing (probably moving somewhere outside the screen).</p>
  
  <p>A search showed that this is usually because of floating point operations. I removed all floats, and Floating Point Model was already on fp:precise for both Debug and Release. I have no idea where to go from here...</p>
  
  <p>I'm pretty sure this code is the source of the errors. Each character can be found in a cell. On the cell edges, the average velocity of the characters there is stored (cell->vLeft etc), and this character wants to average it's own velocity with that stored on the cell edges.</p>
  
  <pre><code>void CharacterQueryStructure_Grid::computeActualVelocity(Character&amp; character, double dt){
  
  // find the cell for this character
  const CellCoord&amp; cellID = _posToCell2D(character.getPosition());
  int x = cellID.first, y = cellID.second;
  int layerID = character.getLayer();
  
  if(x == -1 &amp;&amp; y == -1){ // if the position is invalid, return no neighbours
      //TODO: ERRORRRR
      //return Point(NULL, NULL);
      character.setNewVelocity_EulerIntegration(character.getPreferredVelocity(), dt);
  }
  else{
  
      //Interpolate between the four points to find the average velocity at that location
      UIC_cell* cell = uicGrids[layerID][_getCellID(x,y)];
  
      double distLeft = (character.getPosition().x - xMin) - cellSize * x;
      double distBot  = (character.getPosition().y - yMin) - cellSize * y;
  
      //First find the interpolated velocity at the location of your projection on the horizontal and vertical axes.
      Point vHor = cell-&gt;vLeft * ((cellSize - distLeft)/cellSize) + cell-&gt;vRight * (distLeft/cellSize);
      Point vVer = cell-&gt;vBot  * ((cellSize - distBot)/cellSize)  + cell-&gt;vTop * (distBot/cellSize);
  
      //Now interpolate these to your location
      double distHor = abs(distLeft - .5 * cellSize);
      double distVer = abs(distBot - .5 * cellSize);
  
      //Point vAverage = vHor * (distHor / (.5 * cellSize)) + vVer * (distVer / (.5 * cellSize));
  
      Point vAverage = (vHor + vVer) / 2;
  
  
      //Calculate the new velocity based on your own preferred velocity, the average velocity and the density in your cell.
      Point newVelo = character.getPreferredVelocity() + (cell-&gt;density / maxDensity) * (vAverage - character.getPreferredVelocity());
  
      // set it, while adhering smoothness constraints
      character.setPreferredVelocity(newVelo);
  }   
  </code></pre>
  
  <p>}</p>
  
  <p>Any help would be greatly appreciated!</p>
  
  <p>Edit: And here is _posToCell2D...</p>
  
  <pre><code>CellCoord CharacterQueryStructure_Grid::_posToCell2D(const Point&amp; pos) const
  {
      int x = (int)floor((pos.x - xMin) / cellSize);
      int y = (int)floor((pos.y - yMin) / cellSize);
  
      // if this coordinate lies outside the grid: return nothing
      if(x &lt; 0 || y &lt; 0 || x &gt;= xNrCells || y &gt;= yNrCells)
          return CellCoord(-1,-1);
  
      // otherwise, return the correct cell ID
      return CellCoord(x,y);
  }
  </code></pre>