Change Accessible initialization strategy.

`Accessible` is now a child of its `Control`. This helps to ensure that everything gets cleaned up as it should. Further, node additions no longer scrape the entire scene.

This may introduce regressions and has only been lightly tested, but without it, `ScreenReader` leaked in various circumstances, including some that caused segfaults on exit.
This commit is contained in:
Nolan Darilek 2020-03-18 08:56:45 -05:00
parent f47450d05d
commit fa9e10b1ea
2 changed files with 5 additions and 10 deletions

View File

@ -606,6 +606,8 @@ func _init(node):
if node.is_in_group("accessible"):
return
node.add_to_group("accessible")
add_to_group("accessibles")
node.add_child(self)
self.node = node
if is_focusable(node):
node.set_focus_mode(Control.FOCUS_ALL)

View File

@ -11,8 +11,6 @@ signal swipe_down
var Accessible = preload("Accessible.gd")
var accessibles = []
export var min_swipe_distance = 5
export var tap_execute_interval = 125
@ -32,8 +30,7 @@ func unfocused(node):
func augment_node(node):
if node is Control:
var accessible = Accessible.new(node)
accessibles.append(accessible)
Accessible.new(node)
if not node.is_connected("focus_entered", self, "focused"):
node.connect("focus_entered", self, "focused", [node])
if not node.is_connected("mouse_entered", self, "click_focused"):
@ -80,17 +77,13 @@ func set_initial_scene_focus(scene):
focus.grab_focus()
func _enter_tree():
get_tree().connect("node_added", self, "augment_tree")
augment_tree(get_tree().root)
get_tree().connect("node_added", self, "augment_node")
connect("swipe_right", self, "swipe_right")
connect("swipe_left", self, "swipe_left")
connect("swipe_up", self, "swipe_up")
connect("swipe_down", self, "swipe_down")
func _exit_tree():
for accessible in accessibles:
accessible.free()
accessibles = []
func press_and_release(action):
var event = InputEventAction.new()
event.action = action