DanielMartinus / Konfetti

Celebrate more with this lightweight confetti particle system 🎊
ISC License
3.13k stars 299 forks source link

Fatal Exception: java.lang.OutOfMemoryError #304

Open NKosyanchuk opened 1 year ago

NKosyanchuk commented 1 year ago

Hi, faced with crash while using compose version of lib:

Fatal Exception: java.lang.OutOfMemoryError
Failed to allocate a 96 byte allocation with 916176 free bytes and 894KB until OOM, target footprint 268435456, growth limit 268435456; giving up on allocation because <1% of heap free after GC.

Here is full stacktrace:

android.graphics.drawable.VectorDrawable.mutate (VectorDrawable.java:389)
**nl.dionsegijn.konfetti.core.emitter.PartyEmitter.getRandomShape (PartyEmitter.kt:160)**
nl.dionsegijn.konfetti.core.emitter.PartyEmitter.createParticle (PartyEmitter.kt:79)
nl.dionsegijn.konfetti.core.emitter.PartyEmitter.createConfetti (PartyEmitter.kt:56)
nl.dionsegijn.konfetti.core.PartySystem.render (PartySystem.kt:32)
nl.dionsegijn.konfetti.compose.KonfettiViewKt$KonfettiView$1$2.invoke (KonfettiView.kt:63)
nl.dionsegijn.konfetti.compose.KonfettiViewKt$KonfettiView$1$2.invoke (KonfettiView.kt:45)
androidx.compose.runtime.MonotonicFrameClockKt$withFrameMillis$2.invoke (MonotonicFrameClock.kt:66)
androidx.compose.runtime.MonotonicFrameClockKt$withFrameMillis$2.invoke (MonotonicFrameClock.kt:66)
androidx.compose.runtime.BroadcastFrameClock$FrameAwaiter.resume (BroadcastFrameClock.kt:42)
androidx.compose.runtime.BroadcastFrameClock.sendFrame (BroadcastFrameClock.kt:71)
androidx.compose.runtime.Recomposer$runRecomposeAndApplyChanges$2$2.invoke (Recomposer.kt:510)
androidx.compose.runtime.Recomposer$runRecomposeAndApplyChanges$2$2.invoke (Recomposer.kt:503)
androidx.compose.ui.platform.AndroidUiFrameClock$withFrameNanos$2$callback$1.doFrame (AndroidUiFrameClock.android.kt:34)
androidx.compose.ui.platform.AndroidUiDispatcher.performFrameDispatch (AndroidUiDispatcher.android.kt:109)
androidx.compose.ui.platform.AndroidUiDispatcher.access$performFrameDispatch (AndroidUiDispatcher.android.kt:41)
androidx.compose.ui.platform.AndroidUiDispatcher$dispatchCallback$1.doFrame (AndroidUiDispatcher.android.kt:69)
android.view.Choreographer$CallbackRecord.run (Choreographer.java:1229)
android.view.Choreographer$CallbackRecord.run (Choreographer.java:1239)
android.view.Choreographer.doCallbacks (Choreographer.java:899)
android.view.Choreographer.doFrame (Choreographer.java:827)
android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:1214)
android.os.Handler.handleCallback (Handler.java:942)
android.os.Handler.dispatchMessage (Handler.java:99)
android.os.Looper.loopOnce (Looper.java:201)
android.os.Looper.loop (Looper.java:288)
android.app.ActivityThread.main (ActivityThread.java:7898)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:548)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:936)
tim4724 commented 1 year ago

I encountered the same issue and I have a possible workaround.

You probably initialise the Emitter using the max() function. emitter = Emitter(duration = 1000, TimeUnit.MILLISECONDS).max(2000)

The issue here is an integer division that clips to 0, tough correct would should be 0.5f. This is the problematic line in the EmiterConfig.kt.

Quick Workaround: The issue does not occur if I use the perSecond() function to initialise the Emitter. emitter = Emitter(duration = 1000, TimeUnit.MILLISECONDS).perSecond(1000)

dazza5000 commented 1 year ago

We have this issue even if we use perSecond

        emitter = Emitter(duration = 2000, TimeUnit.MILLISECONDS).perSecond(50),
DanielMartinus commented 9 months ago

Is it reproducible? If so, did you run the memory profiler? Can you reproduce it in a sample project?

Any info you can provide would be helpful.

dazza5000 commented 9 months ago

I can check for some more details, but we get this in Firebase crash reports