melihhakanpektas / flutter_midi_pro

MIT License
14 stars 8 forks source link

[Bug] Crashes with big soundfonts #1

Closed kurenai-11 closed 3 months ago

kurenai-11 commented 11 months ago

Hey. Recently found this lib, works great, but I noticed that it crashes when you try to use big (hundreds of mb) .sf2 files. Tried to load 379mb one, crashed, but, for reference, other 214mb one works for me.

Device: Redmi Note 12 OS: Android 13 Crash log:

Performing hot restart...                                               
Restarted application in 1,951ms.
D/AudioTrack(10119): [audioTrackData][fine] 60s(f:60047 m:7262 s:3202 k:0) : pid 10119 uid 10331 sessionId 41129 sr 44100 ch 2 fmt 1
D/AudioTrack(10119): set(sessionId=0), mcallback is 1
D/AudioTrack(10119): set(): streamType -1, sampleRate 44100, format 0x1, channelMask 0x3, frameCount 5292, flags #0, notificationFrames 0, sessionId 0, transferType 3, uid -1, pid -1
W/AudioTrack(10119): Use of stream types is deprecated for operations other than volume control
W/AudioTrack(10119): See the documentation of AudioTrack() for what to use instead with android.media.AudioAttributes to qualify your playback use case
D/AudioTrack(10119): start(5704): prior state:STATE_STOPPED
I/ect_ear_trainer(10119): Waiting for a blocking GC Alloc
I/ect_ear_trainer(10119): Waiting for a blocking GC Alloc
I/ect_ear_trainer(10119): Clamp target GC heap from 274MB to 256MB
I/ect_ear_trainer(10119): Background concurrent copying GC freed 239348(5684KB) AllocSpace objects, 0(0B) LOS objects, 2% free, 250MB/256MB, paused 47us,28us total 213.396ms
I/ect_ear_trainer(10119): WaitForGcToComplete blocked Alloc on Background for 209.657ms
I/ect_ear_trainer(10119): Starting a blocking GC Alloc
I/ect_ear_trainer(10119): WaitForGcToComplete blocked Alloc on Background for 95.931ms
I/ect_ear_trainer(10119): Starting a blocking GC Alloc
I/ect_ear_trainer(10119): Waiting for a blocking GC Alloc
I/ect_ear_trainer(10119): WaitForGcToComplete blocked Alloc on Background for 24.119ms
I/ect_ear_trainer(10119): Starting a blocking GC Alloc
I/ect_ear_trainer(10119): Starting a blocking GC Alloc
I/ect_ear_trainer(10119): Starting a blocking GC Alloc
I/ect_ear_trainer(10119): Clamp target GC heap from 269MB to 256MB
I/ect_ear_trainer(10119): Alloc concurrent copying GC freed 425138(9218KB) AllocSpace objects, 0(0B) LOS objects, 4% free, 245MB/256MB, paused 43us,23us total 143.193ms
I/ect_ear_trainer(10119): Starting a blocking GC Alloc
I/ect_ear_trainer(10119): Starting a blocking GC Alloc
I/ect_ear_trainer(10119): Alloc young concurrent copying GC freed 8(31KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 253MB/256MB, paused 31us,21us total 6.703ms
I/ect_ear_trainer(10119): Forcing collection of SoftReferences for 3418KB allocation
I/ect_ear_trainer(10119): Starting a blocking GC Alloc
I/ect_ear_trainer(10119): Clamp target GC heap from 277MB to 256MB
I/ect_ear_trainer(10119): Alloc concurrent copying GC freed 4176(304KB) AllocSpace objects, 0(0B) LOS objects, 1% free, 253MB/256MB, paused 27us,31us total 215.397ms
W/ect_ear_trainer(10119): Throwing OutOfMemoryError "Failed to allocate a 3500150 byte allocation with 2799720 free bytes and 2734KB until OOM, target footprint 268435456, growth limit 268435456" (VmSize 13091272 kB)
I/ect_ear_trainer(10119): Starting a blocking GC Alloc
I/ect_ear_trainer(10119): Starting a blocking GC Alloc
I/ect_ear_trainer(10119): Forcing collection of SoftReferences for 3418KB allocation
I/ect_ear_trainer(10119): Starting a blocking GC Alloc
I/ect_ear_trainer(10119): Clamp target GC heap from 277MB to 256MB
I/ect_ear_trainer(10119): Alloc concurrent copying GC freed 15(32KB) AllocSpace objects, 0(0B) LOS objects, 1% free, 253MB/256MB, paused 27us,28us total 215.008ms
W/ect_ear_trainer(10119): Throwing OutOfMemoryError "Failed to allocate a 3500152 byte allocation with 2783400 free bytes and 2718KB until OOM, target footprint 268435456, growth limit 268435456" (VmSize 13091272 kB)
E/AndroidRuntime(10119): FATAL EXCEPTION: main
E/AndroidRuntime(10119): Process: com.example.perfect_ear_trainer, PID: 10119
E/AndroidRuntime(10119): java.lang.OutOfMemoryError: Failed to allocate a 3500152 byte allocation with 2783400 free bytes and 2718KB until OOM, target footprint 268435456, growth limit 268435456
E/AndroidRuntime(10119):        at cn.sherlock.com.sun.media.sound.ModelByteBuffer.loadAll(ModelByteBuffer.java:274)
E/AndroidRuntime(10119):        at cn.sherlock.com.sun.media.sound.SoftSynthesizer.loadSamples(SoftSynthesizer.java:264)
E/AndroidRuntime(10119):        at cn.sherlock.com.sun.media.sound.SoftSynthesizer.loadInstruments(SoftSynthesizer.java:274)
E/AndroidRuntime(10119):        at cn.sherlock.com.sun.media.sound.SoftSynthesizer.loadAllInstruments(SoftSynthesizer.java:654)
E/AndroidRuntime(10119):        at com.melihhakanpektas.flutter_midi_pro.FlutterMidiProPlugin.onMethodCall(FlutterMidiProPlugin.kt:44)
E/AndroidRuntime(10119):        at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:258)
E/AndroidRuntime(10119):        at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/AndroidRuntime(10119):        at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)
E/AndroidRuntime(10119):        at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/AndroidRuntime(10119):        at android.os.Handler.handleCallback(Handler.java:942)
E/AndroidRuntime(10119):        at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(10119):        at android.os.Looper.loopOnce(Looper.java:211)
E/AndroidRuntime(10119):        at android.os.Looper.loop(Looper.java:300)
E/AndroidRuntime(10119):        at android.app.ActivityThread.main(ActivityThread.java:8395)
E/AndroidRuntime(10119):        at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(10119):        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:559)
E/AndroidRuntime(10119):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:954)
W/OOMEventManagerFK(10119): Failed to mkdir /data/miuilog/stability/memleak/heapdump/
I/Process (10119): Process is going to kill itself!
I/Process (10119): java.lang.Exception
I/Process (10119):      at android.os.Process.killProcess(Process.java:1344)
I/Process (10119):      at com.android.internal.os.RuntimeInit$KillApplicationHandler.uncaughtException(RuntimeInit.java:181)
I/Process (10119):      at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1073)
I/Process (10119):      at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1068)
I/Process (10119):      at io.flutter.embedding.engine.dart.DartMessenger.handleError(DartMessenger.java:419)
I/Process (10119):      at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:300)
I/Process (10119):      at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)
I/Process (10119):      at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
I/Process (10119):      at android.os.Handler.handleCallback(Handler.java:942)
I/Process (10119):      at android.os.Handler.dispatchMessage(Handler.java:99)
I/Process (10119):      at android.os.Looper.loopOnce(Looper.java:211)
I/Process (10119):      at android.os.Looper.loop(Looper.java:300)
I/Process (10119):      at android.app.ActivityThread.main(ActivityThread.java:8395)
I/Process (10119):      at java.lang.reflect.Method.invoke(Native Method)
I/Process (10119):      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:559)
I/Process (10119):      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:954)
I/Process (10119): Sending signal. PID: 10119 SIG: 9
Lost connection to device.
melihhakanpektas commented 3 months ago

It may be fixed in the new version, but there will be problems until the Android method changes. Because the desktop Java library is used on the Android platform. Ios and Macos have their own libraries for this.