Skip to content

Fix crash when opening the gallery - #3326

Merged
FrayxRulez merged 1 commit into
developfrom
gallery-convertof-null
Aug 10, 2026
Merged

Fix crash when opening the gallery#3326
FrayxRulez merged 1 commit into
developfrom
gallery-convertof-null

Conversation

@FrayxRulez

Copy link
Copy Markdown
Collaborator

Crash

NullReferenceException: Object reference not set to an instance of an object.

Reported by crash telemetry on 12.9.0.0.

0  Telegram.Controls.Gallery.GalleryWindow.ConvertOf
   Telegram/Controls/Gallery/GalleryWindow.xaml.cs:702
1  GalleryWindow_obj1_Bindings.Invoke_M_ConvertOf_413110846
2  GalleryWindow_obj1_Bindings.CompleteUpdate
3  GalleryWindow_obj1_Bindings.Update
4  Telegram.Controls.Gallery.GalleryWindow.Load
   Telegram/Controls/Gallery/GalleryWindow.xaml.cs:793
5  Telegram.Controls.Gallery.GalleryWindow.ShowAsyncInternal
   Telegram/Controls/Gallery/GalleryWindow.xaml.cs:442

Cause

ConvertOf is a function binding:

<TextBlock Text="{x:Bind ConvertOf(ViewModel.SelectedItem, ViewModel.Position, ViewModel.TotalItems), Mode=OneWay}" />

and it dereferences its first argument straight away:

private string ConvertOf(GalleryMedia item, int index, int count)
{
    if (item.IsPersonal)

Load calls Bindings.Update(), which evaluates every binding once, including this one —
before ViewModel.SelectedItem has been assigned. The stack shows exactly that path, so
the first evaluation on open runs with a null item.

ConvertCaption, a few lines below in the same file, already guards its input
(string.IsNullOrEmpty(text?.Text)); this one was just missed.

Fix

Return an empty string when there is no item yet. The binding re-evaluates as soon as
SelectedItem is set, so the label fills in normally.

Verification

Not built or run — a UWP/.NET Native build is not available in the environment this was
prepared in. The edited file was checked with Roslyn (CSharpSyntaxTree.ParseText) and
parses with no syntax errors; that confirms syntax only, not type checking.

🤖 Generated with Claude Code

ConvertOf is an x:Bind function binding over ViewModel.SelectedItem, and
Bindings.Update runs from Load before an item has been selected, so the very
first evaluation dereferenced a null GalleryMedia.

ConvertCaption in the same file already guards its input the same way.

Reported by crash telemetry on 12.9.0.0.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@FrayxRulez
FrayxRulez merged commit 0d1ab88 into develop Aug 10, 2026
1 check passed
@FrayxRulez
FrayxRulez deleted the gallery-convertof-null branch August 10, 2026 12:42
FrayxRulez added a commit that referenced this pull request Aug 10, 2026
ConvertOf is an x:Bind function binding over ViewModel.SelectedItem, and
Bindings.Update runs from Load before an item has been selected, so the very
first evaluation dereferenced a null GalleryMedia.

ConvertCaption in the same file already guards its input the same way.

Reported by crash telemetry on 12.9.0.0.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant