C#: Fix crash with DisposablesTracker_OnGodotShuttingDown
#78157
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #77486
Also Fixes #77305
As described in the issue, because
DisposablesTracker_OnGodotShuttingDown
is called after getting rid of all script bindings, if deleting an object also deletes other objects that are later in the queue of managed objects to delete, the later managed object isn't marked as deleted and later a use-after-free occurs.Thus move the
DisposablesTracker_OnGodotShuttingDown
call to before deleting the script bindings.(Also the
finalizing
member is probably no longer needed, but I didn't test that)MRP for the original issue: Test_77486_min.zip (ASAN only, simply start the project and close it again)
While I don't think this ha any side-effects beyond a slightly degraded shutdown performance, @neikeq should probably review this as there may be reasons to do things in the previous order that I missed.
Alternatively the root cause is that the managed shutdown deletes objects that are not owned by the managed side, but there is no way to check this.