godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
88.82k stars 20.14k forks source link

Multiple anonymous RefCounted wrapped in Signal/Callable in function argument scope are freed early #95812

Open c5tefz opened 3 weeks ago

c5tefz commented 3 weeks ago

Tested versions

System information

Godot v4.3.stable - Windows 10.0.22631

Issue description

Multiple anonymous RefCounted wrapped in Signal/Callable to be passed as function arguments will be freed early, except for that last one.

Steps to reproduce

Set the code attached at MRP into the scene node and run it. Wherever it is executed, the result is the same as following:

false
false
true

I would expect it all to be true (or all to be false).

Minimal reproduction project (MRP)

extends Node

class AnonRef:
    func fun() -> void: pass

static func _receiver(fun1: Callable, fun2: Callable, fun3: Callable) -> void:
    print(fun1.get_object() is not null)
    print(fun2.get_object() is not null)
    print(fun3.get_object() is not null)

func _ready() -> void:
    _receiver(
        AnonRef.new().fun,
        AnonRef.new().fun,
        AnonRef.new().fun)
AThousandShips commented 3 weeks ago

Can you check if this is affected by:

c5tefz commented 3 weeks ago

Thanks. I think this is exactly the relevant issue. I could not find it before posting. Sorry for the trouble!

AThousandShips commented 3 weeks ago

No worries! This is a bit separate so as long as this PR fixes it this should be kept open, will test if it fixes this later today or tomorrow