From 8bc6ac6fca92bdb5db8822e93f3078e9e4506a4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sierpi=C5=84ski?= <33436839+sierpinskid@users.noreply.github.com> Date: Fri, 21 Nov 2025 14:25:22 +0100 Subject: [PATCH] Try fix SubscribeToTracksAsync NullReferenceException --- .../{0.8.8.meta => 0.8.10.meta} | 2 +- .../Runtime/Core/LowLevelClient/RtcSession.cs | 39 +++++++++++++++++-- 2 files changed, 36 insertions(+), 5 deletions(-) rename Assets/Samples/Stream Video & Audio Chat SDK/{0.8.8.meta => 0.8.10.meta} (77%) diff --git a/Assets/Samples/Stream Video & Audio Chat SDK/0.8.8.meta b/Assets/Samples/Stream Video & Audio Chat SDK/0.8.10.meta similarity index 77% rename from Assets/Samples/Stream Video & Audio Chat SDK/0.8.8.meta rename to Assets/Samples/Stream Video & Audio Chat SDK/0.8.10.meta index 930522ae..5c01a157 100644 --- a/Assets/Samples/Stream Video & Audio Chat SDK/0.8.8.meta +++ b/Assets/Samples/Stream Video & Audio Chat SDK/0.8.10.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 8301a8cd552e38641bc9878e664f2535 +guid: 5857a0f7a3ac47c4c8276106ec8da89d folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Packages/StreamVideo/Runtime/Core/LowLevelClient/RtcSession.cs b/Packages/StreamVideo/Runtime/Core/LowLevelClient/RtcSession.cs index 5b071c7e..a1c0f854 100644 --- a/Packages/StreamVideo/Runtime/Core/LowLevelClient/RtcSession.cs +++ b/Packages/StreamVideo/Runtime/Core/LowLevelClient/RtcSession.cs @@ -552,6 +552,7 @@ private void ClearSession() ActiveCall = null; CallState = CallingState.Unknown; + _httpClient = null; _trackSubscriptionRequested = false; _trackSubscriptionRequestInProgress = false; @@ -601,10 +602,11 @@ private void TryExecuteSubscribeToTracks() /// private async Task SubscribeToTracksAsync() { - if (ActiveCall.Participants == null || !ActiveCall.Participants.Any()) + if (ActiveCall?.Participants == null || !ActiveCall.Participants.Any()) { #if STREAM_DEBUG_ENABLED - _logs.Error($"{nameof(SubscribeToTracksAsync)} Ignored - No participants in the call to subscribe tracks for"); + _logs.Error( + $"{nameof(SubscribeToTracksAsync)} Ignored - No participants in the call to subscribe tracks for"); #endif return; @@ -640,7 +642,7 @@ private async Task SubscribeToTracksAsync() return; } - if (response.Error != null) + if (response?.Error != null) { _logs.Error(response.Error.Message); } @@ -655,6 +657,12 @@ private IEnumerable GetDesiredTracksDetails() foreach (var participant in ActiveCall.Participants) { + if (participant == null) + { + _logs.Error("Cannot subscribe to tracks - participant is null"); + continue; + } + if (participant.IsLocalParticipant) { continue; @@ -668,9 +676,16 @@ private IEnumerable GetDesiredTracksDetails() //This was before changing the IUpdateableFrom.UpdateFromDto //to extract UserId from User obj + var userId = GetUserId(participant); + if (string.IsNullOrEmpty(userId)) + { + _logs.Error($"Cannot subscribe to {trackType} - participant UserId is null or empty. SessionID: {participant.SessionId}"); + continue; + } + yield return new TrackSubscriptionDetails { - UserId = GetUserId(participant), + UserId = userId, SessionId = participant.SessionId, TrackType = trackType, Dimension = requestedVideoResolution.ToVideoDimension() @@ -1067,8 +1082,15 @@ private void OnSfuDominantSpeakerChanged(DominantSpeakerChanged dominantSpeakerC private void OnSfuWebSocketOnError(SfuError obj) { _sfuTracer?.Trace(PeerConnectionTraceKey.SfuError, obj); + if (CallState == CallingState.Offline) + { + return; + } + _logs.Error( $"Sfu Error - Code: {obj.Error_.Code}, Message: {obj.Error_.Message}, ShouldRetry: {obj.Error_.ShouldRetry}"); + + //StreamTODO: add event here } private void OnSfuPinsUpdated(PinsChanged pinsChanged) @@ -1164,6 +1186,15 @@ private async Task RpcCallAsync(TRequest request { //StreamTodo: use rpcCallAsync.GetMethodInfo().Name; instead debugRequestName + if (_httpClient == null) + { + var errorMsg + = $"[RPC Call: {debugRequestName}] Failed - Attempted to execute RPC call but HttpClient is not yet initialized. " + + $"CallState: {CallState}, ActiveCall: {ActiveCall != null}, SessionId: {SessionId ?? "null"}"; + _logs.Error(errorMsg); + throw new InvalidOperationException(errorMsg); + } + var skipTracing = debugRequestName == nameof(GeneratedAPI.SendStats); // Trace the RPC request (except SendStats to avoid noise)