Skip to content

[.NET] Skip serializing delegates with a disposed target #102837

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

Merged
merged 1 commit into from
Jun 13, 2025

Conversation

raulsntos
Copy link
Member

When reloading assemblies, we serialize the managed delegates so we can recreate the callables later. If the delegate's target is a GodotObject that has already been disposed, we can't serialize the delegate.

Before this change, trying to serialize one of these delegates throws an exception and prevents releasing its strong GCHandle, so the assembly can't be unloaded.

With this change, we don't serialize the delegates and release them anyway. This means some delegates may get lost on reloading assemblies, but if their target was already freed it's probably fine.

When reloading assemblies, we serialize the managed delegates so we can recreate the callables later. If the delegate's target is a GodotObject that has already been disposed, we can't serialize the delegate.

Before this change, trying to serialize one of these delegates throws an exception and prevents releasing its strong GCHandle, so the assembly can't be unloaded.

With this change, we don't serialize the delegates and release them anyway. This means some delegates may get lost on reloading assemblies, but if their target was already freed it's probably fine.
@beicause
Copy link
Contributor

beicause commented Feb 16, 2025

Tested locally, it indeed fixes #102484, and also fixes the unloading issue in my another project with a more complex infinite loop tween using TweenMethod TweenCallback , although some errors are printed in the console when rebuilding.

Copy link
Member

@paulloz paulloz left a comment

Choose a reason for hiding this comment

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

Looks good. Will have to test thoroughly, the serialization / reload process is somewhat fragile. But I can't think of any side effect that'd be worse than the current behaviour.

@raulsntos raulsntos marked this pull request as ready for review June 12, 2025 19:06
@raulsntos raulsntos requested a review from a team as a code owner June 12, 2025 19:06
@akien-mga akien-mga merged commit 7e9b709 into godotengine:master Jun 13, 2025
20 checks passed
@akien-mga
Copy link
Member

Thanks!

@raulsntos raulsntos deleted the dotnet/fix-reload-callables branch June 14, 2025 18:49
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.

.NET: Failed to unload assemblies when using TweenMethod/TweenCallback in tool script
5 participants