Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: app crash with vector2i in for()  (Read 1148 times)

0 Members and 1 Guest are viewing this topic.

Soul

  • Newbie
  • *
  • Posts: 44
    • View Profile
app crash with vector2i in for()
« on: May 11, 2014, 04:39:25 pm »
Hey, i have this code
it work fine
void Map::Draw( sf::RenderWindow &wnd)
{
    if(isDraw)
    {
        for(int i=0; i<TileList.size();i++)
        {
            for(int j=0; j<TileList[i].size();j++)
            {
                if(TileList[i][j]->SpriteX==-1&&TileList[i][j]->SpriteY==-1)
                {
                    rect.setPosition( (TileList[i][j]->X*tilesize)+(Pos.x*tilesize), (TileList[i][j]->Y*tilesize)+(Pos.y*tilesize));
                    wnd.draw(rect);
                }
                else
                {
                    TileSet.setPosition( (TileList[i][j]->X*tilesize)+(Pos.x*tilesize), (TileList[i][j]->Y*tilesize)+(Pos.y*tilesize));
                    TileSet.setTextureRect( sf::IntRect(TileList[i][j]->SpriteX*tilesize, TileList[i][j]->SpriteY*tilesize,tilesize, tilesize) );
                    wnd.draw(TileSet);
                }
            }
        }
    }
}


but when i do something like this, the app will crash, why?
void Map::Draw( sf::RenderWindow &wnd)
{
    if(isDraw)
    {
        for(int i=0; i<Pos.x+10;i++)
        {
            for(int j=0; j<Pos.y+10;j++)
            {
                if(TileList[i][j]->SpriteX==-1&&TileList[i][j]->SpriteY==-1)
                {
                    rect.setPosition( (TileList[i][j]->X*tilesize)+(Pos.x*tilesize), (TileList[i][j]->Y*tilesize)+(Pos.y*tilesize));
                    wnd.draw(rect);
                }
                else
                {
                    TileSet.setPosition( (TileList[i][j]->X*tilesize)+(Pos.x*tilesize), (TileList[i][j]->Y*tilesize)+(Pos.y*tilesize));
                    TileSet.setTextureRect( sf::IntRect(TileList[i][j]->SpriteX*tilesize, TileList[i][j]->SpriteY*tilesize,tilesize, tilesize) );
                    wnd.draw(TileSet);
                }
            }
        }
    }
}

Geheim

  • Full Member
  • ***
  • Posts: 201
    • View Profile
    • Email
Re: app crash with vector2i in for()
« Reply #1 on: May 11, 2014, 06:25:08 pm »
because you probably are out of range of the container.
Try to debug your project yourself, then you will see it.
Failing to succeed does not mean failing to progress!