Sign in to follow this  

[C++] Problem emulating slot reels in code

This topic is 3726 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

This topic is 3726 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this