-
-
Notifications
You must be signed in to change notification settings - Fork 22k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
completed-signal for coroutines with more than one yield #17291
Conversation
The error was probably related to me not storing references before. That's fixed now, but I'd still appreciate it if someone had a look and told me if I am handling the references correctly. |
modules/gdscript/gdscript_function.h
Outdated
@@ -234,6 +234,7 @@ class GDScriptFunctionState : public Reference { | |||
GDScriptFunction *function; | |||
GDScriptFunction::CallState state; | |||
Variant _signal_callback(const Variant **p_args, int p_argcount, Variant::CallError &r_error); | |||
GDScriptFunctionState* previousState; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Godot's C++ code uses snake_case
for all identifiers, should be previous_state
.
Could you squash the commits together? Commits 2 and 3 are fixups of the first one, so we only need the final state. |
…ine now, allowing to yield for completion of a function with more than one yield inside.
If it's ok I would use the opportunity to remove the code duplication in that place. |
Yeah that would be nice :) |
Tested, the code makes sense, and I think the struggle is real :) Thanks! |
@hpvb Any chance this will be added in 3.0.3? |
Cherry picked into 3.0.3 |
This is a proposal in response to issue #17280.
You can yield for completion of a coroutine like this:
yield(coroutine(), "completed")
but without this PR that only works for coroutines with one yield inside, since every yield keyword returns a GDScriptFunctionState and the completed-signal was only emitted for the last one.
NOTE: there's probably something missing yet - it causes an error that I don't quite understand (Object::disconnect warns that the signal "completed" didn't exist) and I assume that referencing the previous GDScriptFunctionStates with raw pointers may not be a good idea since it probably won't make sure that the previous states aren't freed before their completed-signal is emitted.