My game crashes if it runs too long

In my PVZ, after I play for a long time, the game crashes, but it’s not a problem with the code for some reason.

game:

Crash screenshot:

2 Likes

i think it’s because the zombies dont auto destroy at the end, and the build up of the causes the game to lag and then eventually crash

1 Like

I think it may be the mass production of zombies which leads to the game crash due to so many sprites being present.

1 Like

so uh u might know me from ur post about this game where i had the picture of the wave of purple zombies, i had my game freeze itself forever. ps (pls add nighttime or wave counter for next update :slight_smile:

1 Like

maybe try putting zombies on auto destroy

1 Like

Yep wave counter and multiple levels will be the next update. I think I’ll do the main menu (I already have the music) after that, then finish all the daytime levels and plants. Night should be pretty easy after that

1 Like

likely a big game (happens with large games) but @richard

also how long around? does it happen if you do nothing? more info is needed

1 Like

@richard , could you help me with this? Apparently this happened cause I ran out of memory and it’s a problem with the editor

After roughly 10-15 minutes of playing normally (I didn’t measure the time so that’s just a guess) The thing is, it doesn’t even lag whatsoever, so IDK why it happens

i played for a while and it didn’t crash for me:

any other hints on how to reproduce this?

3 Likes

Yeah this happens with almost all my games after 30 minutes to an hour of playtime. I think it is a problem on makecode’s end.

2 Likes

So I added some code to the On A Button Pressed block:


To figure out if one of these was getting completely with sprites and well…

Turns out you need just about 1000 sprites hanging around in an array before the game completely breaks, so that’s neat!
Anyways, like I explained to you in your own topic, sprites do not get removed from arrays when they die. They still exist. You have to remove them yourself! Instead of making your own variable to keep track of them all, simply use the “array of sprites of kind (sun)” block to keep track of them instead:

Sprites do get removed from this block when they die, and once there are no more references to a sprite it gets cleared by the garbage collector and cannot hog up all the memory anymore. So just replace your variable with this one, and don’t forget to remove the block that adds them to that currentSun array!

5 Likes

So… @WoofWoof found out why it crashed, in my currentSun array, when a sun is deleted, I FORGOT TO REMOVE IT FROM THE ARRAY. So that meant that after thousands of empty sprites amassed in the array, the editor just kills itself

4 Likes

im still confused what happened to mine

2 Likes

Well you said the game froze, so thats probably the hundreds of sprites lagging it out​:rofl:

1 Like