Game freezes and displays a stream of command line errors

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

After running my main scene for about 30 seconds, the game freezes up, forcing me to stop the scene and restart. This seems to only happen when my character has fired a gun. The error that shows up repeatedly on the console is posted belows:

ERROR: Map<class ShapeOwner2DSW *,int,struct Comparator<class ShapeOwner2DSW *>, class DefaultAllocator>::_set_color: Condition ' p_node == _data._nil && p_color == RED ' is true.
    At: c:\projects\godot-builds\godot\core\map.h:158

I am working on Godot v2.1.3.
Any engineers out there that can tell me why my game is freezing up?

EDIT: Gun, Bullet, and Player Scripts are below:

Gun:

extends Node2D
export var fire_rate = 0.2
export var bullet_scene_path = "res://Assets/bullet0.tscn"
export var bullet_setting = ""

var bullet_offset = Vector2(0,0)
var time_to_next_shot = 0.0
var bullet_holder #The node that contains the bullet nodes
var player
var timer = Timer.new()
var bullet_scn

func _ready():
 bullet_offset = get_node("SpawnPosition2D").get_pos()
 player = get_parent()
 bullet_holder = player.get_parent()

 if(bullet_setting != ""):
	 var setting = get_node("/root/global").get(bullet_setting)
	 bullet_scn = load(str(bullet_scene_path.basename(), "_", setting, ".", 
bullet_scene_path.extension()))
 else:
	 bullet_scn = load(bullet_scene_path)

 set_fixed_process(true)

func _fixed_process(delta):
 time_to_next_shot -= delta

func shot():
 if (time_to_next_shot <= 0):
	 var rotation = player.get_rot()+rand_range(-0.01,0.01)
	 var bullet = bullet_scn.instance()
	 if(not bullet extends RigidBody2D):
		 var holder = bullet
		 for child in holder.get_children():
			 if(child extends RigidBody2D):
				 holder.remove_child(child)
				 bullet = child
		 holder.queue_free()
	 bullet_holder.add_child(bullet)
	 bullet.set_pos(player.get_pos() + bullet_offset.rotated(rotation))
	 bullet.force = Vector2(0,bullet.BULLET_SPEED).rotated(rotation)

	 bullet.source = get_parent().get_parent()
	 time_to_next_shot = fire_rate
	 Input.start_joy_vibration(player.device,player.trigger,player.trigger,0.01)
else:
	 pass
	

Bullet:

extends RigidBody2D

export var BULLET_SPEED = 1000
export var take_player_speed = 3000
export var time_left = 5.0
export var damage = 1.0

var dangerous = true
var force = Vector2(0,0)
var source
var collision = false

func _ready():
 set_fixed_process(true)


func _fixed_process(delta):
 time_left -= delta
 if(time_left <= 0.0):
	 dangerous = false
	 queue_free()

 if(dangerous):
	 set_linear_velocity(get_linear_velocity() + force)
	 force = force.linear_interpolate(Vector2(0,0),delta*4)
	

Player:

extends KinematicBody2D

export var MAX_HEALTH = 8
export var MOVEMENT_SPEED = 2500
export(PackedScene) var bullet0_scene
var trigger
var time_to_next_shot = 0.0
var device = 0
var playerSprite
var direction
var health
var points = 0
var who_killed_me
var speed_holder
var weaponHeld

func _ready():
 set_fixed_process(true)
 health = MAX_HEALTH
 speed_holder = MOVEMENT_SPEED
 weaponHeld = "basic"

func _fixed_process(delta):
 time_to_next_shot -= delta
 var force = Vector2(0,0)
 MOVEMENT_SPEED = speed_holder
 var motion = Vector2(Input.get_joy_axis((device), JOY_ANALOG_0_X), Input.get_joy_axis((device), JOY_ANALOG_0_Y))
 motion = motion.normalized()*MOVEMENT_SPEED*delta
 if ((Input.get_joy_axis(device, JOY_ANALOG_0_X))>0.5|| (Input.get_joy_axis(device, JOY_ANALOG_0_Y))>0.5||(Input.get_joy_axis(device, JOY_ANALOG_0_X))<-0.5||(Input.get_joy_axis(device, JOY_ANALOG_0_Y))<-0.5):
	 move(motion)
 var direction = Vector2(Input.get_joy_axis((device), JOY_ANALOG_1_X),Input.get_joy_axis((device),JOY_ANALOG_1_Y))
 var angle = direction.angle()
 if ((Input.get_joy_axis(device, JOY_ANALOG_1_X))>0.5|| (Input.get_joy_axis(device, JOY_ANALOG_1_Y))>0.5||(Input.get_joy_axis(device, JOY_ANALOG_1_X))<-0.5||(Input.get_joy_axis(device, JOY_ANALOG_1_Y))<-0.5):
	 set_rot(angle)
 if (is_colliding()):
	 var n = get_collision_normal()
	 motion = n.slide(motion)
	 move(motion)
 trigger = Input.get_joy_axis(device, JOY_ANALOG_R2)
 if (trigger > 0.5):
	 if (weaponHeld == "basic"):
		 get_node("Gun0").shot()


func percent_damage_taken(from): #See living_object.gd for more info
 if(from !=self):
	 return 1.0
 return 0

func damage(from, amount):
 var percent = percent_damage_taken(from)
 if(percent !=0):
	 who_killed_me = from
	 update_health(-amount)
	 return true
 return false

func die():
 set_layer_mask(0)
 set_collision_mask(0)
 add_player_points()
 queue_free()
 #display player score

func add_player_points():
 if(who_killed_me != null):
	 who_killed_me.add_points(self.points)

func add_points(points_external):
 points += points_external

func get_percent_life(val):
 var temp_health = health
 temp_health += val
 if(temp_health>MAX_HEALTH):
	 health=MAX_HEALTH
 elif(temp_health<0):
	 health=0
 else:
	 health+=val
 var percent = health/MAX_HEALTH
 return percent

If happens when you fire a gun, maybe there is a weird code somewhere related to that gun (some kind of loop).

More information about your scene and scripts will be needed for better answers.

eons | 2017-07-16 20:45

Thanks, all the scripts have now been added, and if more information about the scenes is needed, I am happy to answer any questions.

Adamant | 2017-07-16 23:50

I’ve fixed a bit the indentation, this thing seems to take tabs only if there is a space…

Anyway, you don’t have multithreading enabled in Physics 2D?
Because there is an issue about it with similar output Physics2D: Multi-Threading · Issue #6512 · godotengine/godot · GitHub

eons | 2017-07-17 01:49

You are awesome. That was the issue. Thanks so much eons.

Adamant | 2017-07-17 02:00

Try (with a copy of the project) the 2.1.4 beta to see if keeps happening there, it has a lot of improvements on the physics server.

Get it from sources or from Releases · GodotBuilder/godot-builds · GitHub

eons | 2017-07-17 13:26