Skip to content

Guard the missing mdia box in the MP4 track picker - #13229

Merged
niksedk merged 1 commit into
mainfrom
fix/pickmp4track-nullable-warning
Aug 5, 2026
Merged

Guard the missing mdia box in the MP4 track picker#13229
niksedk merged 1 commit into
mainfrom
fix/pickmp4track-nullable-warning

Conversation

@niksedk

@niksedk niksedk commented Aug 5, 2026

Copy link
Copy Markdown
Member

Clears the one warning left in the UI project, noticed while building #13226.

PickMp4TrackViewModel.cs(66,31): warning CS8602: Dereference of a possibly null reference.

Why it warned

Initialize(List<Trak>, string) builds each display row from five track.Mdia members - four dereferenced unconditionally, and Duration guarded with track.Mdia?.Minf?.... That ?. puts track.Mdia into maybe-null state, and the state is carried back over the foreach edge, so the first access in the next iteration (line 66) is the one that warns. libse is nullable-oblivious, so nothing outside this loop contributes.

Is it reachable

Not today. Every call site goes through Mp4Parser.GetSubtitleTracks(), which already filters on trak.Mdia != null && trak.Mdia.Minf?.Stbl != null:

But Initialize is public and accepts any List<Trak> - Moov.Tracks unfiltered would NRE - and the mixed style left it ambiguous which way the method meant to lean. So this guards rather than suppresses.

Change

The track's mdia is read once into a local and the row is skipped when it is absent; the remaining Minf?.Stbl? chain stays, since those really can be missing on a track that has an mdia.

Left alone

Export() has the same unguarded chain - track.Mdia.IsVobSubSubtitle at line 141, then track.Mdia.Minf.Stbl three times at 149-151. It does not warn (no ?. on Mdia in that method to seed the state) and it is equally unreachable, but it is the same latent NRE. Out of scope here - happy to fold it in if you want the file consistent.

Verification

  • dotnet build src/ui/UI.csproj -c Release - 0 warnings, 0 errors (was 1 warning)
  • dotnet test tests/UI/UITests.csproj -c Release - 1360 passed, 0 failed

🤖 Generated with Claude Code

PickMp4TrackViewModel.Initialize dereferenced track.Mdia unconditionally
for four members and then guarded it with ?. for the fifth. The compiler
carried that maybe-null state back over the loop edge, so the first
unguarded access warned:

    PickMp4TrackViewModel.cs(66,31): warning CS8602: Dereference of a
    possibly null reference.

Mp4Parser.GetSubtitleTracks() drops mdia-less traks, so no shipping call
path can hit it today - but Initialize takes any List<Trak>, and the
mixed style left it ambiguous which way the code meant to lean.

The track's mdia is now read once into a local and skipped when absent,
which settles the question and drops the UI project to zero warnings.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@niksedk
niksedk merged commit d42cf65 into main Aug 5, 2026
1 check passed
@niksedk
niksedk deleted the fix/pickmp4track-nullable-warning branch August 5, 2026 04:13
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