The computer freezes when running games

Godot Version

4.x

Question

I have developed a tower defense game. When I export the game and run it, the game sometimes freezes when loading levels, with the GPU usage reaching 100%. Subsequently, the computer freezes and becomes unresponsive, requiring a restart.

I can’t find the reason because it only occurs occasionally. Typically, it appears during the first export run after I make changes to the content, and then it runs normally afterwards.
The same situation applies to the game I sent to my friends, and I believe it’s the same for players who purchased my game, hence the high refund rate.

I have tried multiple versions of Godot, but the situation remains the same.

My game in steam:


That sounds like a loop in the init code not exiting. Can you post the code from around when it freezes?

this is my code:

func _ready() -> void:
	
	Engine.time_scale=1.0

	map_custom.map_init(self,$audio/mob_end)

	mob_empty=load("res://MOB/mob_empty.tscn")

	ghost_tscn=load("res://MOB/ghost/mob_ghost.tscn")
	ghost_pro_tscn=load("res://MOB/ghost/mob_ghost_pro.tscn")
	
	one_eye_tscn=load("res://MOB/One_eyed_monster/mob_One_eyed_monster.tscn")
	one_eye_pro_tscn=load("res://MOB/One_eyed_monster/mob_One_eyed_monster_pro.tscn")
	
	bull_s_tscn=load("res://MOB/bull_square/mob_bull_square.tscn")
	bull_s_pro_tscn=load("res://MOB/bull_square/mob_bull_square_pro.tscn")

I’m just puzzled why it sometimes freezes and sometimes doesn’t. It’s hard for me to reproduce the issue, making it extremely difficult to troubleshoot

I think it has something to do with exporting, because I have never experienced any freezing issues when running the level scene in the editor.

I used this plugin to obfuscate the code, and I’m not sure if it’s related

What I’m wondering is, if somewhere in the code (like, say, map_custom.map_init()) there’s a loop that can become endless if it gets the wrong random value.

“Occasionally the CPU goes to 100% and it freezes forever.” sounds to me like it’s spinning in a loop and the exit condition for that loop is never firing. If it only happens sometimes, it’s probably a specific value that does it, and a random number generator or something similar that occasionally generates the bad value.

1 Like

It’s probably not a problem with map_init, because even if I delete it, it still freezes

(post deleted by author)

2 Likes