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

Author Topic: Adding a counter makes an access writing violation?  (Read 1283 times)

0 Members and 1 Guest are viewing this topic.

crumpetxxix

  • Newbie
  • *
  • Posts: 9
    • View Profile
Adding a counter makes an access writing violation?
« on: August 31, 2012, 05:57:02 pm »
Ok so this is more of a general help question versis sfml based but please hear me out because i couldnt find any solution for this online

In my game, the maps / movement are supposed to work like in pokemon where your character stays centered on the screen and the map moves around you, which is handeled by a camera manager holding which hold a cell which then hold the tiles and any object on the screen which needs to be moved when you move. Although that isnt the exact problem at the moment.  Because of how i want the game to be set up the map consists of 64x64 tiles which are linked together by a database and loaded into the game.  Fine so far, but here is the problem.  When im doing the initial load into my game which takes a double array of of tiles and puts them into the active camera cells i get an access read violation when i use a counter within the loop.. Let me show you instead of just sayinf my problem

Code: [Select]
int xCnt = 0, yCnt = 0;
for (int coordX = (thisPlayer.regionX - 5); coordX < (thisPlayer.regionX + 6); coordX++)
{
for (int coordY = (thisPlayer.regionY - 4); coordY < (thisPlayer.regionY + 5); coordY++)
{
theCam.activeCells[xCnt][yCnt].setLocalX(xCnt);
theCam.activeCells[xCnt][yCnt].setLocalY(yCnt);
if (!mnger.LoadTile(thisPlayer.regionID, coordX, coordY, theCam.activeCells[xCnt][yCnt].mTile))
{
return false;
}
if (theCam.activeCells[xCnt][yCnt].mTile.tileType == 1)
{
theCam.activeCells[xCnt][yCnt].mTile.tileTexture = grassBGImg;
}
else if (theCam.activeCells[xCnt][yCnt].mTile.tileType == 2)
{
theCam.activeCells[xCnt][yCnt].mTile.tileTexture = dirtBGImg;
}
else
{
theCam.activeCells[xCnt][yCnt].mTile.tileTexture = grassBGImg;
}
theCam.activeCells[xCnt][yCnt].mTile.tileSprite.setTexture(theCam.activeCells[xCnt][yCnt].mTile.tileTexture);
theCam.activeCells[xCnt][yCnt].mTile.tileSprite.setPosition(theCam.activeCells[xCnt][yCnt].getXPos(), theCam.activeCells[xCnt][yCnt].getYPos());
yCnt++;
}
xCnt++;
}
^ is the piece of code which is giving me the access writing violation, and the actual line which is giving me the error is
Code: [Select]
xCnt++;I cant understand for the life of me why this counter is breaking my game, please help

crumpetxxix

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Adding a counter makes an access writing violation?
« Reply #1 on: August 31, 2012, 06:44:30 pm »
Fixed, i realized i shouldnt have initiliazed the yCnt = 0; above both loops and stuck it in between the loops so it would reset to 0 instead of becoming larger than my array size