0 votes

Hey. I created particles with physics (they are rigid bodies) and I added an AnimationPlayer node to queuefree() them after a few seconds. I added the queuefree function in a script running on each rigid body particle.
The problem is that, when the AnimationPlayer runs the queuefree function after a few seconds, the game crashes and I get a Stack Overflow (Stack Size: 1024) error message. Do I have to manually resize the stack or is there another way to queuefree scenes via the animation player?

Scene structure:

-RigidBody2D
---CollisionShape2D
---Sprite
---AnimationPlayer (calling queue_free())
---VisibilityNotifier2D (to remove when it's outside of the window)

Code:

func queue_free():
    queue_free()

Error:

Stack Overflow (Stack Size: 1024)

asked Jun 28 in Engine by Frenggie (27 points)

1 Answer

+2 votes
Best answer

The code:

func queue_free():
    queue_free()

is causing the stack overflow error by recursively calling itself, which pushes a frame onto the stack, until there is no more allocated space for new stack frames: the overflow error.

The Fix

Remove the code you have posted. queue_free() is defined on Node. Just call the queue_free() function on the target node you want to free.

answered Jun 28 by indicainkwell (108 points)
selected Jun 28 by Frenggie

Thanks for the reply, but I already tried calling queuefree() from the AnimationPlayer itself by not including it into the script, so it would call the default queuefree() function from godot, which didn't work for me.

Sounds like the cause of your issue is somewhere else. Try creating a MCVE to post. You may also identify the cause in the process.

I tried removing the queuefree() call from the AnimationPlayer and instead used a Timer which queuefree()s the parent node on timeout. It works now.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.