Kagami / vmsg

:musical_note: Library for creating voice messages
https://kagami.github.io/vmsg/
Creative Commons Zero v1.0 Universal
348 stars 58 forks source link

memory access out of bounds #25

Open RamboWasReal opened 5 years ago

RamboWasReal commented 5 years ago

When i try to record more than 8min i receive this error. (in google chrome) anybody know's how to remedy ?

Uncaught RuntimeError: memory access out of bounds at wasm-function[11]:24 at wasm-function[254]:86 at wasm-function[241]:34 at vmsg_flush (blob:) at onmessage (blob:)

thank you

Kagami commented 5 years ago

Thanks for report, David. I will check it.

RamboWasReal commented 5 years ago

I searched online and I did not foud anything to help me. I'm not a profesionnal, so if you know where to look in the code to correct the situation please tell me and I will try to solve it on my own.

Thanks.

0xAlwaysDumpling commented 5 years ago

Anyone know how to solve this problem? I am trying to record audio up to 30 minutes.

a-h-abid commented 5 years ago

Hi @Kagami, have you managed to solve this issue? I'm also having trouble when trying to record more than 15mins.

oleg-preply commented 5 years ago

Hi! I've faced the same on the 8th minute.

The reason might be the memory limit set in the package to 16MB. The obvious way seems to try to increase it, but:

In the same time, I've tried to increase only TOTAL_MEMORY to 50MB (but didn't recompile .wasm) and succeeded in the recording of 15minutes :tada: So maybe .wasm module is already compiled with a bigger value? Also, I'm wondering how it can affect mobile devices, where OS memory limits might be lower :thinking:

@Kagami do you think the increase of TOTAL_MEMORY is a legit solution?

Thanks in advance!

Kagami commented 5 years ago

Hi, @oleg-preply. It's ok to bump TOTAL_MEMORY, you don't need to recompile wasm module for that. Basically WebAssembly.Memory is an array of bytes you create for your wasm module, so you can use any size it would need. Browsers might not allow to allocate really big e.g. 1GB memory arrays but 100-200MB should be fine even on mobile.

When I was creating this library I thought 16MB is enough for most MP3 records, but seems like it's not. We should either allow to setup TOTAL_MEMORY value via option passed to record/Recorder. Or send compressed MP3 samples from worker to main thread right away, as described in #23.

Second option is better because memory would be consumed in a more optimal way, without allocating MP3 twice, first at worker and then at main thread and spawning wasm module with a lot of memory. But first option is easier to implement and should be ok as short-term solution.

(Btw, it's also possible to grow memory on demand, but I haven't implemented it either.)