Fix DrawableOsuHitObject
not properly cleaning up dim application callbacks
#29933
+24
−9
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.
Should fix #28629.
First of all, to support the claim that this does fix the issue - reproduction is rather difficult, but I believe I found a way to maximise the chances of it reproducing by performing the following steps:
Now to explain what the fix is.
In the issue thread I spent a considerable time hemming and hawing about which of the dimmable pieces was null, which was a complete miss and a failure at reading. Let's see the stack trace again:
Line 101, you say? What could be null here?
osu/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs
Line 101 in bd8addf
Okay, what's
InitialLifetimeOffset
, then?osu/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuHitObject.cs
Line 108 in bd8addf
Yes, that's right. It's
HitObject
that is null here.Now why does that happen? First, let's note that all stacks where this died went through
UpdateState()
, which means that the problematicapplyDim()
calls had to beApplyCustomUpdateState
event callbacks. Meaning that the pieces whereHitObject
was null were DHOs themselves.Recall that parent DHOs and child DHOs are pooled separately. Therefore, there is no guarantee that any parent and child DHOs will remain associated with each other for the entire duration of a gameplay session; it is quite the contrary, and nobody should rely on that. Unfortunately for us, adding a
applyDimToDrawableHitObject
callback to a child object'sApplyCustomUpdateState
implicitly creates such an association, because it ends up allocating a closure that capturesthis
(meaning the parent in this context).Therefore, this now creates a situation where a child DHO can attempt to read state from a former parent DHO which can be in an indeterminate state, and in fact, when this crashes, the former parent DHO is most likely not even in use - hence the null
HitObject
.Thus, the fix is to clear the association by unsubscribing from the event when nested objects are cleared.
My hypothesis why the reproduction scenario is like it is, is that both the sleep and the increased pressure on the pool (by way of selecting all objects and therefore forcing the DHOs to be materialised beyond pool capacity) increases the likelihood of getting a crosslink. When pool pressure is low, it is much more likely that a parent DHO will get the same child DHO again on re-application, even though that is not guaranteed.
Just as an additional detail, note that the sentry issue for this lists the "first seen" version as 2024.312.0, which is the release that included #27401 (notably authored by yours truly) which would be directly responsible for this mess.