Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


#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