TGViewer
Telegram github commits and releases Telegram github commits and releases @tgappsupdates · 4.52K subscribers
Post #20500 175
UnigramDev/Unigram/crash-sharetarget-null-window • 235fc66 • 1 files, +19/-2
Fix crash activating the app as a share target without a window context

InitializeFrame dereferenced WindowContext.Current unconditionally:

if (WindowContext.Current.Content == null)
{
WindowContext.Current.Content = CreateRootElement(e, WindowContext.Current);
}

WindowContext._current is [ThreadStatic]. It is assigned by the constructor,
which OnWindowCreated calls, and cleared again in OnShutdownCompleted when the
view's dispatcher shuts down. An activation arriving on a view that has been
through that shutdown therefore finds no context, and the app dies with a
NullReferenceException before it has a window.

Its only caller already allows for exactly this:

if (WindowContext.Current?.Content == null)
{
InitializeFrame(e);
}

The null-conditional makes a missing context indistinguishable from missing
content, so the branch is taken and InitializeFrame is called precisely when
there is nothing to dereference.

Build the context instead of assuming one. That is what OnWindowCreated would
have done, and it leaves the frame actually initialized rather than merely not
crashing, so the activation still gets a usable window. Where there is no
Window.Current either, there is nothing to build against; log and return.

Reported by crash telemetry on 12.8.1, all of it through OnShareTargetActivated,
and the code is unchanged on develop.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

#unigram
  • 🫡 2
More from @tgappsupdates
  1. Oct 15, 2026TGX-Android/Telegram-X/main • a6c184f • 6 files, +29/-2 Windows Compile Fixes (#1107) #tgx…
  2. Oct 14, 2026morethanwords/tweb/master • c120515 • 6 files, +22/-0 Composer: an Article item in the att…
  3. Oct 14, 2026morethanwords/tweb/master • fefad9f • 20 files, +314/-70 Unread voices, a playlist that re…
  4. Oct 14, 2026telegramdesktop/tdesktop/dev • c317da9 • 5 files, +90/-27 Use whitelisted domains from API…
  5. Oct 14, 2026TGX-Android/Telegram-X/main • 275879f • 1 files, +1/-0 Add `USE_FULL_SCREEN_INTENT` permis…
  6. Oct 14, 2026TGX-Android/Telegram-X/main • df7245d • 1 files, +6/-2 Update `docs` #tgxandroid
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →