Alright guys,
I am soo close to getting done with the Tile Rendering portion of my game, but I have run into a problem that seems unsolvable. I am running this code:
sf::View view = App->getView();
/* Culling code */
int startX = (view.getCenter().x - view.getSize().x)/TILE_WIDTH;
int endX = (view.getCenter().x + view.getSize().x)/TILE_WIDTH;
int startY = (view.getCenter().y - view.getSize().y)/TILE_HEIGHT;
int endY = (view.getCenter().y + view.getSize().y)/TILE_HEIGHT;
if(startX > MAP_WIDTH)
startX = MAP_WIDTH;
if(startX < 0)
startX = 0;
if(startY > MAP_HEIGHT)
startY = MAP_HEIGHT;
if(startY < 0)
startY = 0;
if(endY > MAP_HEIGHT)
endY = MAP_HEIGHT;
if(endY < 0)
endY = 0;
if(endX > MAP_WIDTH)
endX = MAP_WIDTH;
if(endX < 0)
endX = 0;
for(int y = startY; y < endY; y++)
{
for(int x = startX; x < endX; x++)
{
m_Sprites[GetTile(x,y)].setPosition(x* TILE_WIDTH,y* TILE_HEIGHT);
App->draw(m_Sprites[GetTile(x,y)]);
}
}
I am getting a segfault when I try to draw the sprites. I also ran valgrind and found there was an invalid write of 4 bytes when I set the position of the sprite. I also found memory is leaking somewhere when I run it but I can't find where :/. I can post my whole .cpp file if need. Anyone have any ideas why I am getting a segfault in this portion of the program? If not, could any of you wonderful people please help me debug it?
Thankyou very much!!
-Brent






