Godot: Dysfunctional signal disconnect after 3.2 beta 4

Created on 18 Dec 2019  路  9Comments  路  Source: godotengine/godot

Godot version:
3.2 beta 4

Issue description:
Disconnecting a signal no longer works from within the function connected to the signal; however, this can be circumvented with call_deferred. Issue does not occur on 3.2 beta 3.

Minimal reproduction project:
Timer Disconnect Bug.zip

breaks compat enhancement core

Most helpful comment

@KoBeWi I will add a proper warning suggesting to use either ONESHOT or DEFERRED

All 9 comments

OMG, I've been debugging a strange error in my game and turns out it's a bug in new beta :/

In my case I'm disconnecting idle_frame from SceneTree, so maybe disconnect isn't working anymore?

Sounds related to @reduz's recent commits. CC @Faless

Hmm well, technically you should not be able to disconnect while the signal is called, that is crash prone or unsafe, so what you were doing was most likely a bug. This is why the _one shot_ and _deferred_ connection flags exist.

I think maybe the best solution is to add a better error report in disconnect(), but this is technically not a bug..

Hmmm, now I noticed that it complains about not being able to disconnect. I just had an assert that relied on this and it made the error go unnoticed for me.

@hoontee Your connect call should look like this

$Timer.connect("timeout", self, "broken", [], CONNECT_ONESHOT)

and remove the disconnect().

This is probably unexpected for people who relied on the old behavior, so it should be mentioned somewhere in the changelog.

@KoBeWi I will add a proper warning suggesting to use either ONESHOT or DEFERRED

@Calinou could you add this as compat change in the changelog?

@reduz @akien-mga Thanks for clarifying this. I agree this fixes bad practice.

However, I found that _"either ONESHOT or DEFERRED"_ is also a bit misleading (although rightfully pointing me to the right direction) since in my case I used to disconnect and reconnect the same signal to the same object and function but with different parameters. ONESHOT alone gives a _ERROR: Signal 'xxx' is already connected to given method 'yyy' in that object_, suggesting that the ONESHOT 'expiration' occurs after the function returns, while I have expected it to occur right before... So I had to use both ONESHOT + DEFERRED in order to disconnect and reconnect the signal from the called function.

@oeleo1 Instead of disconnecting and reconnecting the signal, perhaps you should use global variables in place of the signal parameters?

@akien-mga Done.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SleepProgger picture SleepProgger  路  3Comments

gonzo191 picture gonzo191  路  3Comments

RebelliousX picture RebelliousX  路  3Comments

bojidar-bg picture bojidar-bg  路  3Comments

ndee85 picture ndee85  路  3Comments