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
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.
Most helpful comment
@KoBeWi I will add a proper warning suggesting to use either ONESHOT or DEFERRED