ankidroid / ankidroid/Anki-Android

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

Đang mở
#19,578 3 bình luận 0 reaction 0 người được giao Xem trên GitHub
2.22 2.23 Keep Open
Ngôn ngữ chính
Kotlin
Star
11.8k
Fork
2.9k
Merge trung bình
2 ngày 3 giờ
Pull request đã merge (30 ngày)
171

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.