Need help debugging weird game crashes with no response from editor

Godot Version

Godot 4.3
Compatibility Renderer

Issue description

In my top-down 2D stealth game, the game freezes for about half a second and then crashes without any error messages in the editor. This happens after returning to the main menu and selecting a new level from the level select screen repeatedly for 2–5 times. Therefore I used Calinou’s custom build to debug in Visual Studio, and got these errors.


Potential Sources of Crash

Using Visual Studio, I discovered that the issue with the relationship between my PatrolPoints script and enemy script. At this point, I’m uncertain how to proceed with debugging. PatrolPoints is a Node2D that the enemy is programmed to follow, upon contact, the enemy follows the next PatrolPoints, allowing me to form patrol paths for my enemies.

PatrolPoint Script:

extends Node2D
class_name PatrolPoints

#The amount of time the enemy idles in a patrol point's position
@export var time_idle: float = 2.0

#A flag that dictates if the enemy should match the PatrolPoints's rotation
@export var match_rotation: bool = false
var pos: Vector2
var rot: float

func _ready() -> void:
    pos = global_transform.origin
    rot = global_transform.basis.get_rotation()

func return_pos() -> Vector2:
    return pos

func return_rotation() -> Vector2:
    # Correct the logic to use global rotation
    return pos + Vector2.RIGHT.rotated(rot) * 90

Enemy Script (Enemy’s Idle State):

func _idle_ready() -> void:
	SignalBus.emit_signal("detection", "Undetected", Color.WHITE, 1)
	animation_tree["parameters/movement_blend_scale/scale"] = 0.5
	footstep_timer.wait_time = 1
	current_speed = patrol_speed

func move_towards_point():
	if next_point:
		move(next_point.return_pos())

func _idle_physics_process(_delta: float) -> void:
	move_towards_point()

# Connected via a navigationagent2D's target_reached signal
func patrol_point_reached():
	if not next_point or patrol_points.size() == 0:
		push_error("next_point is invalid or patrol_points is empty.")
		return
	
	if hsm and hsm.get_active_state() and hsm.get_active_state().name == "Idle":
		stay_still_timer.wait_time = next_point.time_idle
		if stay_still_timer.is_stopped():
			stay_still_timer.start()
		await stay_still_timer.timeout
		
		counter += 1
		if patrol_points.size() == 1:
			return
		if counter >= patrol_points.size():
			counter = 0
			if backtrack:
				patrol_points.reverse()
		next_point = patrol_points[counter]
	else:
		push_error("hsm or active state is invalid.")

Other details

Sometimes this error very rarely shows up when successfully loading a new level scene, I’m unsure of what it means.

I tried using other custom builds to debug the game crashes except the crashes never occurred in any of the other custom builds I compiled with VS.

Lastly I tried reproducing this issue but the crashes never came up in my minimum reproduction project here. Hopefully it can at least be used to give an idea of what my project is. Example 1 is an example of a scene that crashes after reloading the scene multiple times, where there is an enemy with patrol points as children. While example 2 is a scenario where no game crashes occur.

That should be reported in the Godot github, hardly you’ll find help for that type of problem here, also a crash is a thing that shoudn’t happen even by user mistake so needs to be fixed in engine code.

1 Like

That makes a lot of a sense, i’ll report this to the github and probably find a workaround then. Thank you for the response!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.