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

fix(scripting/lua): Fix not closing to-be-closed variables on error #2427

Merged
merged 1 commit into from
May 28, 2024

Conversation

kajkul
Copy link
Contributor

@kajkul kajkul commented Mar 18, 2024

Goal of this PR

Call __close metamethod on to-be-closed variables (added in Lua 5.4) when an uncaught error occurs. Before this change variables would be closed only if the function/event/script execution ended without an error.

How is this PR achieving the goal

This PR calls the lua_resetthread method, when handling an error case, which unwinds the stack and closes all to-be-closed variables present there.

This PR applies to the following area(s)

ScRT: Lua

Successfully tested on

Platforms: Windows

Checklist

  • Code compiles and has been tested successfully.
  • Code explains itself well and/or is documented.
  • My commit message explains what the changes do and what they are for.
  • No extra compilation warnings are added by these changes.

@github-actions github-actions bot added the ScRT: Lua Issues/PRs related to the Lua scripting runtime label Mar 18, 2024
@gottfriedleibniz gottfriedleibniz self-assigned this Mar 18, 2024
@github-actions github-actions bot added the invalid Requires changes before it's considered valid and can be (re)triaged label Mar 18, 2024
@kajkul
Copy link
Contributor Author

kajkul commented Mar 18, 2024

Don't know why the checks failed. It doesn't look like anything related to with this PR.

@github-actions github-actions bot added triage Needs a preliminary assessment to determine the urgency and required action and removed invalid Requires changes before it's considered valid and can be (re)triaged labels Mar 19, 2024
@gottfriedleibniz
Copy link
Contributor

gottfriedleibniz commented Mar 21, 2024

Actually. Would it be possible to call lua_resetthread prior to invoking FORMAT_STACK_TRACE? That execution path is not exception-free. ... In fact, it would probably be best if we wrapped that FxNativeInvoke::Invoke invocation in a try/catch

LGTM.

@gottfriedleibniz gottfriedleibniz added ready-to-merge This PR is enqueued for merging and removed triage Needs a preliminary assessment to determine the urgency and required action ready-to-merge This PR is enqueued for merging labels Mar 21, 2024
@gottfriedleibniz
Copy link
Contributor

Amended previous message, just a few concerns that should probably be addressed.

@kajkul
Copy link
Contributor Author

kajkul commented Mar 22, 2024

Actually. Would it be possible to call lua_resetthread prior to invoking FORMAT_STACK_TRACE?

I guess it might get the wrong stack trace if an error occurs during closing a variable.

That execution path is not exception-free. ... In fact, it would probably be best if we wrapped that FxNativeInvoke::Invoke invocation in a try/catch

Just did that.

@github-actions github-actions bot added the triage Needs a preliminary assessment to determine the urgency and required action label Mar 22, 2024
@gottfriedleibniz gottfriedleibniz added ready-to-merge This PR is enqueued for merging and removed triage Needs a preliminary assessment to determine the urgency and required action labels May 7, 2024
@github-actions github-actions bot added the triage Needs a preliminary assessment to determine the urgency and required action label May 9, 2024
@prikolium-cfx prikolium-cfx merged commit 603f8ca into citizenfx:master May 28, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge This PR is enqueued for merging ScRT: Lua Issues/PRs related to the Lua scripting runtime triage Needs a preliminary assessment to determine the urgency and required action
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants