Rdot icon indicating copy to clipboard operation
Rdot copied to clipboard

Computeds persist after their scenes are destroyed and error when they try to update

Open jdtjenkins opened this issue 1 year ago • 1 comments

Hi, just reporting a bug, not sure if I can fix it in userland or not!

When you create a computed in a scene, then change scene or otherwise that scene then gets freed - any computed (and I assume effects, though I haven't tested that) persist, so when they try and update again they error. So we need some way to remove computeds from the graph or something I think.

I have included an example project which reproduces the error and included some instructions in the main scene. test-rdot-computed.zip

Thank you for creating this, coming to Godot from JS here and Rdot is amazing

jdtjenkins avatar Sep 18 '24 15:09 jdtjenkins

So we need some way to remove computeds from the graph or something I think.

So this actually seems to work perfectly... If you have a computed, then remove it from the graph on scene tree exit

extends Node2D

@onready var thingLabel: Label = $ThingLabel

var thingComputed = R.computed(func(_ignore):
	return "Thing Doubled:" + str(Global.thingDoubled.value)
)

func _ready():
	R.bind(thingLabel, "text", thingComputed)

func _exit_tree() -> void:
	var graph = RdotGraph.getInstance()
	
	graph.consumerDestroy(thingComputed.node)

So this is using the RdotGraph internal, and I think this works? Wonder if it's worth having a less "internal-y" way of doing this?

jdtjenkins avatar Sep 18 '24 15:09 jdtjenkins