@@ -25,7 +25,9 @@ import com.getcode.theme.GradientSpec
2525import com.getcode.theme.White
2626import com.getcode.ui.utils.toAGColor
2727import com.getcode.util.resources.ResourceHelper
28+ import com.getcode.utils.TraceType
2829import com.getcode.utils.decodeBase64
30+ import com.getcode.utils.trace
2931import androidx.lifecycle.ViewModel
3032import com.getcode.view.LoadingSuccessState
3133import kotlinx.coroutines.flow.MutableStateFlow
@@ -91,15 +93,28 @@ abstract class BaseAccessKeyViewModel(
9193 }
9294
9395 viewModelScope.launch(dispatchers.IO ) {
94- val accessKeyBitmap = createBitmapForExport(drawBackground = true , words = words, entropyB64 = entropyB64)
95- val accessKeyBitmapDisplay = createBitmapForExport(drawBackground = false , words, entropyB64)
96- val accessKeyCroppedBitmap =
97- Bitmap .createBitmap(accessKeyBitmapDisplay, 0 , 500 , 1200 , 1450 )
98-
99- uiFlow.update {
100- it.copy(
101- accessKeyBitmap = accessKeyBitmap,
102- accessKeyCroppedBitmap = accessKeyCroppedBitmap
96+ runCatching {
97+ val accessKeyBitmap = createBitmapForExport(drawBackground = true , words = words, entropyB64 = entropyB64)
98+ val accessKeyBitmapDisplay = createBitmapForExport(drawBackground = false , words, entropyB64)
99+ val accessKeyCroppedBitmap =
100+ Bitmap .createBitmap(accessKeyBitmapDisplay, 0 , 500 , 1200 , 1450 )
101+
102+ uiFlow.update {
103+ it.copy(
104+ accessKeyBitmap = accessKeyBitmap,
105+ accessKeyCroppedBitmap = accessKeyCroppedBitmap
106+ )
107+ }
108+ }.onFailure { error ->
109+ if (error is kotlin.coroutines.cancellation.CancellationException ) throw error
110+ // Bitmap rendering can fail on some OEM devices with
111+ // "width and height must be > 0". Report as a non-fatal instead
112+ // of crashing; the UI handles null bitmaps. Refs Bugsnag 6a4528ca.
113+ trace(
114+ tag = " access-key" ,
115+ message = " Failed to render access key bitmap" ,
116+ error = error,
117+ type = TraceType .Error ,
103118 )
104119 }
105120 }
0 commit comments