Why the scene crashes only if movement comes after get_collider().queue_free()?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Francesco Cicala
:warning: Old Version Published before Godot 3 was released.

I have two KinematicBody2D (both with Sprite and CollisionShape2D as children), the first one moving toward the second one, so that after few seconds they collide.
Here two situations very similar except for the position of the “move” command:

#First situation

extends KinematicBody2D

func _ready():
    set_fixed_process(true)

func _fixed_process(delta):
    move(Vector2(0,2)) #before the 'if'-->the scene doesn't crash
	if (is_colliding()):
	    var other = get_collider()
	    other.queue_free()

#Second situation

extends KinematicBody2D

func _ready():
    set_fixed_process(true)

func _fixed_process(delta):
	if (is_colliding()):
	    var other = get_collider()
	    other.queue_free()
    move(Vector2(0,2))   #put after the 'if' ---> the scene crashes at the contact

As in the comments, the first code makes the scene to proceed very well before, during and after the contact: no crashes and the moving body continue on his trajectory.
When I use the second code, the scene crashes when the moving object collides with the second object.
The error message is "“Invalid call. Nonexistent function ‘queue_free’ in base ‘Nil’.”’
I can’t explain this behaviour, could you explain it to me? Thank you guys

Weird, I think the second is_colliding should be always false because is checking before move…

The script is only on one body?

eons | 2016-12-26 12:04

Oh, i forgot the error message: “Invalid call. Nonexistent function ‘queue_free’ in base ‘Nil’.”
Why should be always false? Yes, only on the moving object

Francesco Cicala | 2016-12-26 12:35

You are trying to remove a body which doesn’t exist. Meaning that, for some reason the get_collider() did not return a body, but the value Nil instead.

Jatz | 2016-12-26 16:18

is_colliding should be false because it is marked true only if is colliding after move (I guess docs should be more detailed on that).

Seems there is some asynchrony for resetting the flag and lets pass the “if” a second time while the body is being deleted.

eons | 2016-12-26 16:20

Complicated stuff, i see :confused: Ahah thank you for the help!

Francesco Cicala | 2016-12-28 09:06

:bust_in_silhouette: Reply From: puppetmaster-

try to disable collision before calling queue_free

other.get_node(collisionNode).set_trigger(false)
other.queue_free()