UnigramDev/Unigram/crash-message-selector-null-content-root • abd63ce • 1 files, +40/-5
Fix crash when MessageSelector loads before its content is realized
MessageSelector.OnLoaded built the TextSelectionManager unconditionally:
_textSelectionManager ??= new TextSelectionManager(this, ContentTemplateRoot);
TextSelectionManager's constructor rejects a null root, so whenever a
container was connected before its ContentPresenter had realized the content,
ContentTemplateRoot was still null and the constructor threw
ArgumentNullException out of a Loaded handler, which is unhandled and takes
the app down.
Reported by crash telemetry on 12.8.2 ("Value cannot be null. Parameter
name: root"). The reported log tails show it under heavy UI churn — chat
navigation with popups opening — which is when layout is most likely to lag
behind connection.
Attach as soon as a root is actually available instead: on load when the
content is already realized, otherwise on the first arrange, by which point
the presenter has always produced one. Selection is therefore attached within
the same layout pass and nothing is lost.
The arrange path is guarded by a field null check, so once attached it costs
one comparison and never allocates.
EnsureTextSelectionManager also checks IsConnected. Only OnUnloaded detaches
the manager, so attaching while disconnected would leave the pointer handlers
on the content root permanently and, through them, root the control for the
rest of the session.
The four selection accessors dereferenced the manager unconditionally, which
would have turned this window into a NullReferenceException instead; they are
now null-safe.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
#unigram
Post #20495
135
- 🫡 2
- 💅 1