is there a limit to how many times a signal can be sent?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By CrazyMonkey

i receive this error: Stack Overflow (Stack Size: 1024)

the error occurs in this function:

func updateGrid(x,y, val):
	print("grid"+str(x)+str(y),val)
	emit_signal("grid"+str(x)+str(y), val)

the last print statement works and prints “grid00X” before crashing

I don’t think it’s the signal causing the issue. Where is this function called?

exuin | 2021-04-20 06:07

Which function is connected to the “grid00” signal? If it’s updateGrid, this would explain the error (since it would cause an infinite loop of function calls).

Thomas Karcher | 2021-04-20 09:29

the function calls this there are a few of them each with a different number value but they all look like this:

func _grid00(val):
	text = val

CrazyMonkey | 2021-04-21 20:57

the function is called in my main node, and it only occurs if I run the program on loop and only after a few hundred iterations.

CrazyMonkey | 2021-04-21 20:59

Then that’s the issue, you have 1024+ stacks. Whatever the code on your main node is, it’s making too many stacks. What’s the main node code?

exuin | 2021-04-21 21:42

what is meant by “stacks” ?
here is the main node

extends Node2D

signal toOai(grid, turn)
signal toXai(grid, turn)
signal winXai(tf)
signal winOai(tf)
signal grid00(val)
signal grid01(val)
signal grid02(val)
signal grid10(val)
signal grid11(val)
signal grid12(val)
signal grid20(val)
signal grid21(val)
signal grid22(val)

var grid = [["","",""],["","",""],["","",""]]

# Called when the node enters the scene tree for the first time.
func _ready():
#	var test = 0
#	var test2 = [[2,4],[2,3]]
#	for i in range(10):
#		print(i)
#
#	if typeof(test) == 1:
#		print('bool()')
	pass # Replace with function body.



#tests if there is a winner 
func winer():
	#print("testWinn")
	for i in range(len(grid)):
		if (grid[0][i] != "" and grid[0][i] == grid[1][i] and grid[0][i] == grid[2][i]):
			#print("1Winn")
			return [true, grid[0][i]]

		elif (grid[i][0] != "" and grid[i][0] == grid[i][1] and grid[i][0] == grid[i][2]):
			#print("2Winn")
			return [true, grid[i][0]]

	if (grid[0][0] != "" and grid[0][0] == grid[1][1] and grid[0][0] == grid[2][2]) :
		#print("3Winn")
		return [true, grid[0][0]]

	elif (grid[0][2] != "" and grid[0][2] == grid[1][1] and grid[0][2] == grid[2][0]) :
		#print("4Winn",grid[0][2])
		
		return [true, grid[0][2]]
	elif not grid[1].has("") and not grid[0].has("") and not grid[2].has(""):
		return [true, "cat's game"]
	
	else:
		return [false, ""]
		


func _StartBT():
	grid = [["","",""],["","",""],["","",""]]
	var turn = 0
	var win = winer()
	while not win[0]:
		#print(turn, grid)
		if not turn % 2:
			#print("Xai's turn")
			emit_signal("toXai", grid, int(turn/2))
		else:
			#print("Oai's turn")
			emit_signal("toOai", grid, int(turn/2))
		win = winer()
		turn += 1
	if win[1] == "X":
		print("x wins")
		for x in grid:
			print(x)
		emit_signal("winXai", 1)
		emit_signal("winOai", 0)
	elif win[1] == "O":
		print("o wins", win)
		for x in grid:
			print(x)
		emit_signal("winXai", 0)
		emit_signal("winOai", 1)
	else:
		print("cat's game")
		for x in grid:
			print(x)
		emit_signal("winXai", 3)
		emit_signal("winOai", 3)

	turn = 0 
	#_StartBT()

func updateGrid(x,y, val):
	#print("grid"+str(x)+str(y),val)
	emit_signal("grid"+str(x)+str(y), val)
	
func _xaiMove(x, y):
	grid[x][y] = "X"
	updateGrid(x,y, "X")
	
	#print(grid, " X")
	

func _oaiMove(x, y):
	grid[x][y] = "O"
	updateGrid(x,y, "O")
	#print(grid, " O")


#func _on_LineEdit_text_changed(new_text):
	#pass # Replace with function body.

CrazyMonkey | 2021-04-21 21:55