[C++] Problem emulating slot reels in code

Started by
1 comment, last by jpetrie 16 years, 6 months ago
We're developing a slots game and somehow I got the idea to experiment emulating slot reels spinning in code by using some kind of list or stack data structure. The reels in the code below are Qt's QList<int>:

for(int i = 1; i <= 7; i++)
{
    reelOne.append(i);
    reelTwo.append(i);
    reelThree.append(i);
    reelFour.append(i);
    reelFive.append(i);
}

while(isSpinning)
{
    int one = reelOne.at(0);
    reelOne.removeAt(0);
    reelOne.append(one);

    int two = reelTwo.at(0);
    reelTwo.removeAt(0);
    reelTwo.append(two);

    int three = reelThree.at(0);
    reelThree.removeAt(0);
    reelThree.append(three);

    int four = reelFour.at(0);
    reelFour.removeAt(0);
    reelFour.append(four);

    int five = reelFive.at(0);
    reelFive.removeAt(0);
    reelFive.append(five);
}






The problem is that I get an "access writing violation" everytime around the fourth reel, no matter what data structure I use or whether its a pointer. So far I've tried this method using QList, QVector, and QStack. Aside from the question of whether this is a good design or even necessary for my purposes (probably won't use this anyway) does anyone know why this code doesn't work properly? Its been bugging me...the only thing I can think is that maybe the loop is too fast for the data to be written and rewritten like that. [Edited by - JimDaniel on October 1, 2007 11:35:25 AM]
Advertisement
...no one has an idea?
Not with the amount of code you've posted, no.

Access violations tend to be caused by errors relatively far away from their actual manifestation. Post more code - as much as you can between the declaration and initialization of those objects and their ultimate failure.

Have you used your debugger?

This topic is closed to new replies.

Advertisement