Repl process died unexpectedly: signal: segmentation fault (core dumped)

Hello everyone. I am having issues with a game I am working on.

My game is basically a survival game using 2D arrays to display the character, enemies, etc. Early on when making this project I can across the error RecursionError: maximum recursion depth exeeded in comparision so I put this snippet of code in:

import sys
sys.setrecursionlimit(999999999)

and that error stopped popping up. Eventually, after playing the game for around a minute, now you get this error:

repl process died unexpectedly: signal: segmentation fault (core dumped)

Basically my game is a 21*23 2d array (or something around there) and in order for enemies to move, trees to grow, etc, I have a function that checks every single individual value in the 2d array to see if its an enemy and it should move, tree that should grow, etc. There is a separate function that checks for enemies and another one that grows trees, rocks, seeds, etc. I believe that this intensive way of checking the grid for things overloads the system after a while, thus giving me the former error. Entering the sys code I thought should have saved me for a while, but I’m not sure.

So basically what I’m asking is if this new error has anything to do with the previous one, with the recursion limit. If so, how do I prevent it, and if not, what does it actually mean?

I published the project so that anyone can look inside
https://replit.com/@schooljash/In-the-Wild?v=1

This is python, for clarification.

1 Like

check the RAM bar in the bottom left corner; is it full?

2 Likes

Maybe try not doing things recursively as much

3 Likes

I have checked the bar, it never even comes close to reaching the maximum. I have noticed, however, that the blue portion grows over time as the project goes on it gets larger. It starts at around 100 MB and when I get around 115MB it does the error. Is there a way to delete unnecessary memory?

2 Likes

I’m assuming the recursion limit is too big, set 999999999 to a smaller number.

2 Likes

Welcome to the community @schooljash !

1 Like

I don’t know exactly what caused your problem, but it’s definitely related to memory. I would say just avoid using recursive everything, especially with python.

1 Like

I ran the program in Visual Studios and everything works perfectly. I’ll probably be using that from now on though thanks for the memory clarification.

If you are using recursion so much that the stack manages to eat up a majority of replits free 512 mb ram provided, it kind of implies that everything is not working perfectly.
The recursion limit exists for this exact reason.
Instead of checking the entire array constantly a better solution is to just have a list of enemy positions or important locations in the array.
I’m sure if you ran it long enough in VS it would also crash locally too, it would just take longer because you have more memory than replit does.

1 Like

I’d like to note that I’ve only ever seen this error when I’ve mistakenly made a function call itself infinitely, causing a very quick OOM crash. I’d recommend limiting the recursion as much as possible, and check that a function isn’t calling itself by mistake

Is there a way to call a function or something that deletes memory so that the crash never happens?

Every time you call a function a stack frame is created with local variables etc.
Imagine a stack of boxes where every time you call a function a box is added.
What you’re doing would be the equivalent of adding a box until you reach the ceiling, and then instead of stopping removing the ceiling and continuing until they reach space and can’t be stacked any more.
You can’t take any boxes out of the middle without destroying the ones on top.

Also if an error gets thrown in one of those functions while it’s like a million calls deep you’re going to have a hard time.

1 Like

Can you delete stack frames? Or are they always needed?

Whenever I get this in C I start crying

no and it wouldn’t be a good solution if you could