ankidroid / ankidroid/Anki-Android

[BUG] `backend.addMediaFile` throws `OutOfMemoryError`

Abierto
#19,578 3 comentarios 0 reacciones 0 asignados Ver en GitHub
2.22 2.23 Keep Open
Lenguaje dominante
Kotlin
Estrellas
11.8k
Forks
2.9k
Merge medio
2 d 3 h
PR fusionados (30 d)
171

Descripción

178MB file: https://ankidroid.org/acra/app/1/bug/360462/report/91d6bb58-e609-440f-9bc0-e021667d50b6

1. We should catch the `Error` and warn the user
2. The backend [`AddMediaFile`](https://github.com/ankitects/anki/blob/dac26ce67147b261d79a56092320cc2f5af0d990/proto/anki/media.proto#L15) only accepts a byte array, not a file reference
* Increasing memory pressure for large files, as it does not support streaming
* We may wish to define an `addMediaFile[ByPath]` in `Anki-Android-Backend`
3. We should warn users on 100MB+ files and verify they want to continue
* AnkiWeb is unlikely to sync them: https://faqs.ankiweb.net/are-there-limits-on-file-sizes-on-ankiweb.html

```
java.lang.OutOfMemoryError: Failed to allocate a 178131144 byte allocation with 50331648 free bytes and 163MB until OOM, target footprint 416188144, growth limit 536870912
at com.google.protobuf.AbstractMessageLite.toByteArray(AbstractMessageLite.java:47)
at anki.backend.GeneratedBackend.addMediaFile(GeneratedBackend.kt:2883)
at com.ichi2.anki.libanki.Media.addFile(Media.kt:69)
at com.ichi2.anki.servicelayer.NoteService.importMediaToDirectory(NoteService.java:144)
at com.ichi2.anki.NoteEditorFragment$addMediaFileToField$1.invokeSuspend$lambda$0(NoteEditorFragment.kt:2079)
at com.ichi2.anki.CollectionManager.withCol$lambda$1(CollectionManager.kt:146)
at com.ichi2.anki.CollectionManager$withQueue$3.invokeSuspend(CollectionManager.kt:128)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.java:111)
at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:99)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:811)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:715)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:702)
Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [r0{Cancelling}@e987957, Dispatchers.Main.immediate]
```

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.