davidliu
Committed by GitHub

Fix crash when setting publishing layers (#559)

  1 +---
  2 +"client-sdk-android": patch
  3 +---
  4 +
  5 +Fix crash when setting publishing layers
@@ -316,6 +316,11 @@ constructor( @@ -316,6 +316,11 @@ constructor(
316 sender: RtpSender, 316 sender: RtpSender,
317 qualities: List<LivekitRtc.SubscribedQuality>, 317 qualities: List<LivekitRtc.SubscribedQuality>,
318 ) { 318 ) {
  319 + if (isDisposed) {
  320 + LKLog.i { "attempted to set publishing layer for disposed video track." }
  321 + return
  322 + }
  323 + try {
319 val parameters = sender.parameters ?: return 324 val parameters = sender.parameters ?: return
320 val encodings = parameters.encodings ?: return 325 val encodings = parameters.encodings ?: return
321 var hasChanged = false 326 var hasChanged = false
@@ -357,8 +362,12 @@ constructor( @@ -357,8 +362,12 @@ constructor(
357 } 362 }
358 363
359 if (hasChanged) { 364 if (hasChanged) {
360 - // This refeshes the native code with the new information  
361 - sender.parameters = sender.parameters 365 + // This refreshes the native code with the new information
  366 + sender.parameters = parameters
  367 + }
  368 + } catch (e: Exception) {
  369 + LKLog.w(e) { "Exception caught while setting publishing layers." }
  370 + return
362 } 371 }
363 } 372 }
364 373