ankidroid / ankidroid/Anki-Android

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

オープン
#19,578 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る
2.22 2.23 Keep Open
主要言語
Kotlin
スター
11.8k
フォーク
2.9k
平均マージ
2日 3時間
マージ済み PR(30日)
171

説明

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]
```

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。