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 double unregistration on dispose of Array. #81230

Merged
merged 1 commit into from
Sep 4, 2023

Conversation

SamiKalliomaki
Copy link
Contributor

@SamiKalliomaki SamiKalliomaki commented Sep 1, 2023

This fixes a small bug where Array tries to unregister itself twice on shutdown.

I have tested this manually and the error is no longer logged on shutdown.

@SamiKalliomaki SamiKalliomaki requested a review from a team as a code owner September 1, 2023 16:23
@AThousandShips AThousandShips added this to the 4.x milestone Sep 1, 2023
@AThousandShips

This comment was marked as outdated.

@SamiKalliomaki SamiKalliomaki changed the title Fix recursive dispose of Array. Fix double unregistration on dispose of Array. Sep 1, 2023
@SamiKalliomaki
Copy link
Contributor Author

I just realized my initial pull request description was nonsense. There is no recursion going on and we can skip the temporary variable.

@SamiKalliomaki
Copy link
Contributor Author

SamiKalliomaki commented Sep 2, 2023

Based on the investigation in the bug, update the PR to instead avoid double registration that seems to be the root cause of the issue.

Copy link
Member

@raulsntos raulsntos left a comment

Choose a reason for hiding this comment

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

Thanks! I read the explanation in #81231 (comment) and I understand what's going on now, I've been able to reproduce the issue and this looks like the correct fix.

It seems we can also remove : this() from the Array<T> constructor that takes T[] array. Although I don't think this one causes any issues, but we can save allocating Array twice:

https://github.com/godotengine/godot/blob/5b2972b57412722fd89737291aff67eaefd1a172/modules/mono/glue/GodotSharp/GodotSharp/Core/Array.cs#L1060

Also, since you are a new contributor, make sure to read CONTRIBUTING.md and the contributing documentation if you haven't already.

You'll need to squash the commits before this PR can be merged. The contributing documentation contains information about squashing in case you need it.

Feel free to reach out in the development chat if you need help.

@raulsntos raulsntos added cherrypick:4.0 cherrypick:4.1 Considered for cherry-picking into a future 4.1.x release labels Sep 2, 2023
@raulsntos raulsntos modified the milestones: 4.x, 4.2 Sep 2, 2023
@SamiKalliomaki
Copy link
Contributor Author

I've squashed the commits as well as removed the one extra "this()" call from the generic version of the Array class.

This fixes a bug where Array would get registered twice with the
DisposablesTracker causing an exception on shutdown.

Fixes godotengine#81231
Copy link
Member

@raulsntos raulsntos left a comment

Choose a reason for hiding this comment

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

LGTM.

@akien-mga akien-mga merged commit 00e14f3 into godotengine:master Sep 4, 2023
@akien-mga
Copy link
Member

Thanks!

@SamiKalliomaki SamiKalliomaki deleted the array-dispose branch September 4, 2023 15:54
@YuriSizov YuriSizov removed the cherrypick:4.1 Considered for cherry-picking into a future 4.1.x release label Sep 21, 2023
@YuriSizov
Copy link
Contributor

Cherry-picked for 4.1.2.

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.

Array - System.ArgumentException: Disposable not registered. (Parameter 'weakReference') on shutdown
5 participants