Using set_deffered() has been bricking my computer, any suggestions?

Godot Version

4.7.1.stable

Question

I read in another thread that when attempting to change the size of the player hitbox, especially if you plan on doing it many times, to just make a hitbox for each size and toggle them as needed. I’ve been using the code below in an attempt to make the player crouch with a keybind but every time I press the key my entire computer is bricked. Any suggestions? Is this a bug or is there something to be careful of when setting this kind of thing up? Any help would be appreciated, thanks!

The code in question:

gd
extends CharacterBody3D

@export var speed = 6
@export var mass = 37
# earth's gravity is ~9.8m*s^-2
@export var gravity = 36
# jump_strength measured in meters per second
@export var jump_strength = 12
# friction should be (0 < f <= 1), normal is ~0.007-0.0085
var friction = 0.015
@onready var animation_player = $blockbench_export/AnimationPlayer

var target_velocity = Vector3.ZERO
var gm = gravity * mass
var active_friction = clamp(friction * gm / 100, 0.001, 1)

#runs on startup
func _ready():
	Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
	$InGameMenu.hide()
	

#runs every frame
func _process(_delta):
	if Input.is_action_just_pressed("open_or_close_menu"):
		if $InGameMenu.visible:
			$InGameMenu.hide()
			Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
		else:
			$InGameMenu.show()
			Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)

func _physics_process(delta) -> void:
	var input_dir = Input.get_vector("walk_left", "walk_right", "walk_forward", "walk_back")
	var direction = transform.basis * Vector3(input_dir.x, 0, input_dir.y)
	if Input.is_action_just_pressed("jump") and is_on_floor():
		target_velocity.y = jump_strength
		animation_player.play("jump")
	if Input.is_action_pressed("shift"):
		pass
	#direction += transform.basis * Vector3(input_dir.x * -6, 0, 0)
	# ctrl is the 'run' button in this game
	if Input.is_action_pressed("ctrl"):
		direction.x *= 2.2
		direction.z *= 2.2
		active_friction *= 1.05
	if Input.is_action_just_pressed("shift"):
		$StandingCollision3D.set_deferred("disabled", true)
		$SlideCollision3D.set_deferred("disabled", false)
		#print("Shift pressed")
	if Input.is_action_just_released("shift"):
		$StandingCollision3D.set_deferred("disabled", false)
		$SlideCollision3D.set_deferred("disabled", true)
		#print("Shift released")
	
	if direction != Vector3.ZERO:
		direction = direction.normalized()
		$Pivot.basis = Basis.looking_at(direction)
		
		target_velocity.x = lerp(velocity.x, direction.x * speed, active_friction)
		target_velocity.z = lerp(velocity.z, direction.z * speed ,active_friction)
	else:
		target_velocity.x = lerp(velocity.x, 0.0, active_friction)
		target_velocity.z = lerp(velocity.z, 0.0, active_friction)
	if abs(velocity.x) > 0.5 or abs(velocity.z) > 0.5:
		animation_player.queue("walk")
	else:
		animation_player.stop()
	
	
	if not is_on_floor():
		target_velocity.y = target_velocity.y - (gravity * delta)
	
	velocity = target_velocity
	move_and_slide()

var sensitivity = 0.002
var pitch = 0.0

func _unhandled_input(event):
	if event is InputEventMouseMotion:
		# Rotate Yaw (Left/Right) - Rotate the whole character/body
		rotate_y(-event.relative.x * sensitivity)
		
		# Rotate Pitch (Up/Down) - Rotate the camera node itself
		pitch -= event.relative.y * sensitivity
		pitch = clamp(pitch, -PI/2, PI/2)
		$Camera3D.rotation.x = pitch

Edit: I’ve pasted the whole script as requested. For context, this is the script running every frame for the player’s avatar, there is very little else going on. Though the problem remains the same.

Please paste the whole script.
Also see Posting guidelines in #Help channel, where you will find instruction how to properly format your code snippets.

I would first try to comment the function calls out and add a print like “pressed ok” and “released ok” to make sure the program doesn’t break from anything else while you think its from the function calls. If the prints show up as expected (once each per press and release) and without any crashes you will know for sure the problem is with the function calls, even though nothing apparent is wrong with them.

That’s a great idea.

Trying this I did see the correct lines printed in the Output and the game kept running smoothly; so I know it’s not something else about when the keybind is pressed. Undoing the print()s and un-commenting the original code ti still bricks my computer, even ctrl+alt+delete does nothing. Thank you for the help, but now I’m still confused why the game is crashing. Do you have any other tests you’d recommend or ideas what might be going on?

Are you sure you want is_action_just_pressed there, not is_action_pressed and is_action_released? With “just” it’s only for one frame, and with your logic with the two if I’m not sure if both are fired at the same frame.
For the logic with “_just” IMHO a structure with if, else would be better than two if.

EDIT: After thinking more about my response … maybe that with the just is not the right suggestion.

Provide more context.

I tried your suggestion of changing the _on_button_released to an elif and it actually worked! I guess it might have had something to do with too many directly competing calls in the same physics frame? Thank you for pointing that out!!