Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix screensaver crash when loading an invalid backdrop image #2567

Merged
merged 1 commit into from
Mar 10, 2023

Conversation

nielsvanvelzen
Copy link
Member

Changes

  • Fix screensaver crash when loading an invalid backdrop image
  • Add logging to getRandomLibraryShowcase

Issues

java.util.concurrent.ExecutionException: com.bumptech.glide.load.engine.GlideException: Failed to load resource
There was 1 root cause:
com.bumptech.glide.load.resource.bitmap.RecyclableBufferedInputStream$InvalidMarkException(Mark has been invalidated, pos: 5150516 markLimit: 5242880)
 call GlideException#logRootCauses(String) for more detail
	at com.bumptech.glide.request.RequestFutureTarget.doGet(RequestFutureTarget.java:217)
	at com.bumptech.glide.request.RequestFutureTarget.get(RequestFutureTarget.java:130)
	at org.jellyfin.androidtv.integration.dream.composable.DreamHostKt$getRandomLibraryShowcase$backdrop$1.invokeSuspend(DreamHost.kt:89)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
	at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
	at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
	Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [androidx.compose.ui.platform.MotionDurationScaleImpl@e683413, androidx.compose.runtime.BroadcastFrameClock@bee2650, StandaloneCoroutine{Cancelling}@5f2e049, AndroidUiDispatcher@a35ed4e]
Caused by: com.bumptech.glide.load.engine.GlideException: Failed to load resource
There was 1 root cause:
com.bumptech.glide.load.resource.bitmap.RecyclableBufferedInputStream$InvalidMarkException(Mark has been invalidated, pos: 5150516 markLimit: 5242880)
 call GlideException#logRootCauses(String) for more detail

@nielsvanvelzen nielsvanvelzen added bug Something isn't working crash Bug causing app crashes labels Mar 4, 2023
@nielsvanvelzen nielsvanvelzen added this to the v0.16.0 milestone Mar 4, 2023
@nielsvanvelzen nielsvanvelzen marked this pull request as ready for review March 5, 2023 09:10
Copy link
Contributor

@DavidFair DavidFair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still getting app crashes with this branch, including on a clean build

(I've got the image rotation time at 5 seconds to quickly cycle to bad images for testing)

ACRA caught a ExecutionException for org.jellyfin.androidtv.debug
java.util.concurrent.ExecutionException: com.bumptech.glide.load.engine.GlideException: Failed to load resource
There was 1 root cause:
com.bumptech.glide.load.HttpException(Failed to connect or obtain data, status code: -1)
 call GlideException#logRootCauses(String) for more detail
	at com.bumptech.glide.request.RequestFutureTarget.doGet(RequestFutureTarget.java:217)
	at com.bumptech.glide.request.RequestFutureTarget.get(RequestFutureTarget.java:130)
	at org.jellyfin.androidtv.integration.dream.composable.DreamHostKt$getRandomLibraryShowcase$backdrop$1.invokeSuspend(DreamHost.kt:92)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
	at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
	at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
	Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [androidx.compose.ui.platform.MotionDurationScaleImpl@67e852c, androidx.compose.runtime.BroadcastFrameClock@c7a4bf5, StandaloneCoroutine{Cancelling}@7b52d8a, AndroidUiDispatcher@ec09ffb]
Caused by: com.bumptech.glide.load.engine.GlideException: Failed to load resource
There was 1 root cause:
com.bumptech.glide.load.HttpException(Failed to connect or obtain data, status code: -1)
 call GlideException#logRootCauses(String) for more detail

@nielsvanvelzen
Copy link
Member Author

Yup I also found that after marking the PR as ready. I believe the issue is that the try-catch should be within the withContext that calls the .get() function.

@nielsvanvelzen nielsvanvelzen marked this pull request as draft March 5, 2023 21:08
@omerinero
Copy link
Contributor

Yup I also found that after marking the PR as ready. I believe the issue is that the try-catch should be within the withContext that calls the .get() function.

The try-catch didn't fix it either. It still crashes, apparently the exception can't be caught.
After a bit of debugging I realised that adding a breakpoint to this line fixed the problem. So it seems to be a timing issue somehow. So I added a .timeout() of one minute and everything works fine. What is causing this and why does the timeout fix it? I still have no idea.

@nielsvanvelzen
Copy link
Member Author

The GlideException was wrapped in a ExecutionException by the Future class. I've moved the try-catch to only run for the Glide call and catch the wrapped exception.

@nielsvanvelzen nielsvanvelzen marked this pull request as ready for review March 10, 2023 20:38
Copy link
Contributor

@DavidFair DavidFair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see the new error appearing in logcat, and it's been running fine for 10+ minutes (where it used to crash in 1-2)

Only nit is it reverts back to the Jellyfin background instead of transparently trying another image for a few seconds, but any crash fix is a great improvement 👍

@omerinero
Copy link
Contributor

Only nit is it reverts back to the Jellyfin background instead of transparently trying another image for a few seconds, but any crash fix is a great improvement +1

Did you try with the timeout ?

@nielsvanvelzen
Copy link
Member Author

Only nit is it reverts back to the Jellyfin background instead of transparently trying another image for a few seconds, but any crash fix is a great improvement 👍

Yeah this is something we need to fix too, I was thinking about some kind of "queue" that preloads the next item when one is already showing. This would also make sure the next item shows after exactly 30 seconds instead of 30 seconds + loading time.

Did you try with the timeout ?

IIRC Glide has a default timeout and this isn't really relevant for this problem.

@nielsvanvelzen nielsvanvelzen merged commit 757efe1 into jellyfin:master Mar 10, 2023
@nielsvanvelzen nielsvanvelzen deleted the dream-backdrop-crash branch March 10, 2023 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working crash Bug causing app crashes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants