Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actualslicer4ever

Posted 23 March 2013 - 07:46 AM

it's saturday morning, this code doesn't cause a crash, but is just an stupid oversight i caught myself doing:

 

 

Tile *World::GetTile(unsigned int x, unsigned int y){ //Same as above, but we can specify x/y coordinates instead of index positions.
    if(x<0 || x>=m_Width ) return nullptr;  //We check that the x-axis is inside the world.
    if(x<0 || y>=m_Height) return nullptr; //We check that the y-axis is inside the world.
    return m_Tiles+(x+y*m_Width);
}

 

completly idiotic on my part, unsigned numbers are never less than zero;-)


#1slicer4ever

Posted 23 March 2013 - 07:45 AM

it's saturday morning, this code doesn't cause a crash, but is just an stupid oversight i caught myself doing:

 

Tile *World::GetTile(unsigned int x, unsigned int y){ //Same as above, but we can specify x/y coordinates instead of index positions.
    if(x<0 || x>=m_Width ) return nullptr;  //We check that the x-axis is inside the world.
    if(x<0 || y>=m_Height) return nullptr; //We check that the y-axis is inside the world.
    return m_Tiles+(x+y*m_Width); //We assume our application is going to be good, and only request tile's inside the appropiate range.
}

 

completly idiotic on my part, unsigned numbers are never less than zero;-)


PARTNERS