Python Forum
Gui slot machine-out of memory error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Gui slot machine-out of memory error
#1
Python V3.72
Windows 7\Linux Mint 19.1

A game I am working on called Freespin Frenzy
crashes after a while with either an "out of memory"
message in the shell, or a "Python has stopped working" pop up,
this is in Windows 7.

The memory is getting eaten up fast by a bad piece of my code that
"spins" the reels, it doesn't actually spin them,
it just flashes all the symbols on top of each other for a short while.

I am sure I am approaching this all wrong, but this is the best
I can do at my current ability level.

Please look at this piece of the code below and see if you can advise me
on how to load in and use the graphics in a way that will
not use up RAM in about 30 mins of play, (I have 8gig ram).

You can get the full source code here if you want:
https://stevepython.wordpress.com/2020/0...-79-update

The game is still a work in progress and I hope to make it look a lot
better in future updates, but I have to get this fixed first really.

Regards, Steve.

def spin_reels():
    """Pseudo spin,pretty poor, but best I can do for now."""

    spinner = ['FH', 'FD', 'FC',
               'WH', 'WD', 'WC',
               'JH', 'JD', 'JC', 'JS',
               'QH', 'QD', 'QC', 'QS',
               'KH', 'KD', 'KC', 'KS',
               'AH', 'AD', 'AC', 'AS',
               'BH', 'BD', 'BC']

    r_one = Label(cards_frame)
    r_two = Label(cards_frame)
    r_three = Label(cards_frame)

    Glo.hold_btn1.configure(state=DISABLED)
    Glo.hold_btn2.configure(state=DISABLED)
    Glo.hold_btn3.configure(state=DISABLED)

    for spins in range(4):

        for spinr in range(18):
            rnd_symb1 = randrange(len(spinner))
            symb1 = spinner[rnd_symb1]+'.png'

            rnd_symb2 = randrange(len(spinner))
            symb2 = spinner[rnd_symb2]+'.png'

            rnd_symb3 = randrange(len(spinner))
            symb3 = spinner[rnd_symb3]+'.png'

            if spins < 1 and not Glo.btn1_is_held:
                r_one = Label(cards_frame)
                PHOTO = PhotoImage(file='cards/gfx/'+str(symb1))
                r_one.config(image=PHOTO)
                r_one.grid(row=0, column=1, padx=2, pady=2)
                r_one.photo = PHOTO
                r_one.update()

            if spins == 1 and not Glo.btn1_is_held:
                card_lbl_one = Label(cards_frame)
                PHOTO = PhotoImage(file='cards/gfx/'+str(Glo.reel_one))
                card_lbl_one.config(image=PHOTO)
                card_lbl_one.grid(row=0, column=1, padx=2, pady=2)
                card_lbl_one.photo = PHOTO
                r_one.update()

            if spins < 2 and not Glo.btn2_is_held:
                r_two = Label(cards_frame)
                PHOTO = PhotoImage(file='cards/gfx/'+str(symb2))
                r_two.config(image=PHOTO)
                r_two.grid(row=0, column=2, padx=2, pady=2)
                r_two.photo = PHOTO
                r_two.update()

            if spins == 2 and not Glo.btn2_is_held:
                card_lbl_two = Label(cards_frame)
                PHOTO = PhotoImage(file='cards/gfx/'+str(Glo.reel_two))
                card_lbl_two.config(image=PHOTO)
                card_lbl_two.grid(row=0, column=2, padx=2, pady=2)
                card_lbl_two.photo = PHOTO
                r_two.update()

            if spins < 3 and not Glo.btn3_is_held:
                r_three = Label(cards_frame)
                PHOTO = PhotoImage(file='cards/gfx/'+str(symb3))
                r_three.config(image=PHOTO)
                r_three.grid(row=0, column=3, padx=2, pady=2)
                r_three.photo = PHOTO
                r_three.update()

            if spins == 3 and not Glo.btn3_is_held:
                spins = 99
                card_lbl_three = Label(cards_frame)
                PHOTO = PhotoImage(file='cards/gfx/'+str(Glo.reel_three))
                card_lbl_three.config(image=PHOTO)
                card_lbl_three.grid(row=0, column=3, padx=2, pady=2)
                card_lbl_three.photo = PHOTO
                r_three.update()

            time.sleep(0.025)
            r_one.destroy()
            r_two.destroy()
            r_three.destroy()

    rnd_hold()
    check_for_win()
    save_bank()
Reply


Messages In This Thread
Gui slot machine-out of memory error - by steve_shambles - May-17-2020, 01:40 PM
RE: Gui slot machine-out of memory error - by Yoriz - May-17-2020, 01:49 PM
RE: Gui slot machine-out of memory error - by Yoriz - May-17-2020, 02:05 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Understanding and debugging memory error crashes with python3.10.10 Arkaik 5 2,108 Apr-18-2023, 03:22 AM
Last Post: Larz60+
  Memory Error While generating cheksum no mg24 2 1,037 Sep-25-2022, 10:33 PM
Last Post: mg24
  Help For Slot Machine Code Rayaan 1 2,716 Mar-30-2020, 05:01 AM
Last Post: SheeppOSU
  Memory consumption grows during execution only on single machine Jendker 2 1,891 Feb-10-2020, 01:57 PM
Last Post: Jendker
  Go around memory error Pytonormen 1 2,085 Oct-19-2019, 04:31 PM
Last Post: Gribouillis
  memory error using permutation list of 11 elements kikidog 1 3,905 Sep-10-2019, 08:22 PM
Last Post: ichabod801
  machine learning error (using jupyter) calonia 1 4,150 Jun-26-2019, 05:16 PM
Last Post: ThomasL
  Fix Memory Error while installing a library for Qgis alexastorga 0 2,589 Apr-13-2018, 04:54 PM
Last Post: alexastorga
  Dictionaries and memory error. jarrod0987 5 5,526 Feb-23-2018, 12:15 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020