Skip to content

Commit 1204737

Browse files
authored
fix: Fix crash when changing video streaming resolution (#778)
* fix * fix
1 parent 4c8965f commit 1204737

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

com.unity.renderstreaming/Runtime/Scripts/StreamSenderBase.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,33 +53,32 @@ public void Done(MediaStreamTrack track)
5353
internal abstract WaitForCreateTrack CreateTrack();
5454

5555

56-
internal virtual void ReplaceTrack(MediaStreamTrack track)
56+
internal virtual void ReplaceTrack(MediaStreamTrack newTrack)
5757
{
58-
if (track == null)
58+
if (newTrack == null)
5959
throw new ArgumentNullException("track", "This argument must be not null.");
6060

61-
if (m_track == Track)
61+
if (m_track == newTrack)
6262
throw new ArgumentException("track", "The value of this argument has already been set.");
6363

6464
/// todo:: If not disposing the old track here, the app will crash.
6565
/// This problem is caused by the MediaStreamTrack when it is destroyed on the thread other than the main thread.
6666
m_track?.Dispose();
67-
68-
m_track = Track;
67+
m_track = newTrack;
6968
foreach (var transceiver in Transceivers.Values)
7069
{
7170
transceiver.Sender.ReplaceTrack(m_track);
7271
}
7372
}
7473

75-
internal void SetTrack(MediaStreamTrack track)
74+
internal void SetTrack(MediaStreamTrack newTrack)
7675
{
77-
if (track == null)
76+
if (newTrack == null)
7877
throw new ArgumentNullException("track", "This argument must be not null.");
7978

8079
if (m_track != null)
81-
throw new InvalidOperationException("Track is not null.");
82-
m_track = track;
80+
throw new InvalidOperationException("Track is not null. Use ReplaceTrack method.");
81+
m_track = newTrack;
8382
}
8483

8584
private MediaStreamTrack m_track;

com.unity.renderstreaming/Runtime/Scripts/VideoStreamSender.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ void StartCoroutine<T>(T coroutine, Action<T> callback) where T : IEnumerator
449449
throw new ArgumentNullException("coroutine");
450450
if (callback == null)
451451
throw new ArgumentNullException("callback");
452-
_Coroutine(coroutine, callback);
452+
StartCoroutine(_Coroutine(coroutine, callback));
453453
}
454454

455455
IEnumerator _Coroutine<T>(T coroutine, Action<T> callback) where T : IEnumerator

0 commit comments

Comments
 (0)