Skip to content
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

Keep GDScript functions in stack while yielding #28884

Merged
merged 2 commits into from
Jul 1, 2019

Conversation

vnen
Copy link
Member

@vnen vnen commented May 14, 2019

This prevents GDScript functions from leaving the stack too soon when they are resuming from yield, allowing the ones expecting it to finish to know the caller.

Helps debugging cases when you use: yield(function_which_yields(), "completed") since now it shows the call that resumed that function.

Also show the function names in the debugger stack, which helps identify the stack (not sure why that was commented out, it's been like this since the first commit). And show function/script/line when resuming from yield after instance is gone, to help identify the issues.

vnen added 2 commits May 14, 2019 11:39
This prevents GDScript functions from leaving the stack too soon when
they are resuming from yield, allowing the ones expecting it to finish
to know the caller.

Helps debugging cases when you use:
`yield(function_which_yields(), "completed")`
since now it shows the call that resumed that function.
Also show script and line when the instance is gone when resuming from
yield.
@vnen
Copy link
Member Author

vnen commented May 14, 2019

This is a remake of #28815 (I thought I could reopen but it's not possible after force-pushing).

@ghost
Copy link

ghost commented May 15, 2019

This will be great, these types of errors have been so difficult to track down. From time to time I have desired a graceful way to check / ignore them, in situations where things are shutting down or the game is closing and yields were out and resuming as resources are vanishing.

@bojidar-bg
Copy link
Contributor

Related to #24199.

@@ -1583,15 +1583,26 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
GDScriptLanguage::get_singleton()->script_frame_time += time_taken - function_call_time;
}

if (ScriptDebugger::get_singleton())
GDScriptLanguage::get_singleton()->exit_function();
bool yielded = retvalue.is_ref() && Object::cast_to<GDScriptFunctionState>(retvalue);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that's the best way to check if the function yielded. This might break in cases such as:

func a():
  yield()
func b():
  var x = a()
  # x.resume()
  return x # Not yielding, yet returning a GDScriptFunctionState

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, but then the completed signal from function also relies on this, so we may need to check it.

I guess we can find a way to check if the state correspond to the same function. Not sure how to do this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can find a way to check if the state correspond to the same function. Not sure how to do this.

Still gameable:

func a():
  var x = b()
  return b(x)
func b(z=null):
  if z != null:
    return z
  else:
    yield()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So is any further change needed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guess it could be fine as-is.

@akien-mga
Copy link
Member

Thanks!

@akien-mga
Copy link
Member

Now that Godot 3.1 has been released, we don't plan to cherry-pick new features and enhancements to the 3.0 branch, unless there is very strong support in favor of it. Removing cherrypick label for 3.0.

@vnen vnen deleted the yield-resume-stack branch May 4, 2022 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants