-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
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
[.NET] Fix serialization of delegates capturing variables #83217
[.NET] Fix serialization of delegates capturing variables #83217
Conversation
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.
I suspect closures weren't really tested thoroughly when this was implemented. This is not an area of the module that I'm very familiar with, so I'm trying to understand why it was implemented this way.
But there are definitely improvements in this PR compared to the current implementation, so if it fixes some cases I think that may be worth merging.
I've also been wondering on and off if serializing these when reloading is actually something we want to do in this case.
I also wonder if serializing these is necessary at all.
0d5fd38
to
c542931
Compare
c542931
to
c310ecc
Compare
I'm removing the |
If it's ready for review, it might be worth it to update the PR description :) |
I think the actual back and forth in the comments is easier to understand than re-writing the history? Long story short:
|
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.
LGTM. Thanks!
Thanks! |
WIP fix for #81903.
Let's use a similar example to the one described in the issue.
As of right now, this PR completely fixes case 1 (crudely: captured variables aren't
GodotObject
).On my way to fixing case 2 (here, we also capture
this
). I had to switch the serialization and callgodotsharp_var_to_bytes()
withp_full_objects = true
. I'm not entirely sure about it, there might be security concerns? Everything now serializes fine (and thus, is properly unloaded). But once we try to deserialize the delegate back,this
(in the example above) is considered as aVBoxContainer
instead of the actual concrete class, resulting in anArgumentException
when we try to use its value. I kinda imagine it's because of the script being unloaded in between, but I can't really think of any good/simple solution here.Hoping for someone to have a stroke of genius, or to rubber duck me in the right direction ❤️
I've also been wondering on and off if serializing these when reloading is actually something we want to do in this case.