Прежде всего, я не опытный программист, поэтому, пожалуйста, будьте снисходительны. :)
Мне было любопытно, что вызывает ошибку под названием «Переполнение стека». Я использую Visual C ++ 2010 Express.
struct elem
{
BITMAP * colltile;
elem * next;
};
/ * введите код здесь * /
int collision_map (unsigned int poz_x, unsigned int poz_y)
{
elem * wsk = this->where_the_head_of_list_is;
int x,y;
x = poz_x%64; //coord x on tile (0-63px)
y = poz_y%64; //coord y on tile (0-63px)
poz_x /= 64; //preparing poz_x and poz_y to point on a tile on a grid
poz_y /= 64; //integers do not have to be floored
//for (int j=(poz_y*(this->size_x)+poz_x); j>0; j--) //normally works... but
for (int j=0; j<1000; j++) //this version is not
{
if ((!(wsk = wsk->next)) ||
((poz_x+1) > this->size_x) ||
((poz_y+1) > this->size_y))
{ //should check if there is no new pointer or just out of map
return -1;
}
}
return getpixel(wsk->colltile, x, y);
}
Почему условие не работает, когда j
достигает значения длины списка?