natario1 / ZoomLayout

2D zoom and pan behavior for View hierarchies, images, video streams, and much more, written in Kotlin for Android.
https://natario1.github.io/ZoomLayout
Apache License 2.0
1.05k stars 147 forks source link

Recurrent crash (reported by Play Store): java.lang.RuntimeException: at com.otaliastudios.zoom.ZoomLayout.onMeasure #225

Open nathanfallet opened 2 years ago

nathanfallet commented 2 years ago

Describe the bug

Please add a clear description of what the bug is, and fill the list below.

Additional information

This library is used via https://github.com/markusressel/KodeEditor that we use in our app

Logs

java.lang.RuntimeException: 
  at com.otaliastudios.zoom.ZoomLayout.onMeasure (ZoomLayout.kt:121)
  at android.view.View.measure (View.java:26207)
  at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:7020)
  at android.widget.LinearLayout.measureChildBeforeLayout (LinearLayout.java:1552)
  at android.widget.LinearLayout.measureHorizontal (LinearLayout.java:1204)
  at android.widget.LinearLayout.onMeasure (LinearLayout.java:723)
  at android.view.View.measure (View.java:26207)
  at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:7020)
  at android.widget.FrameLayout.onMeasure (FrameLayout.java:194)
  at android.view.View.measure (View.java:26207)
  at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:7020)
  at android.widget.FrameLayout.onMeasure (FrameLayout.java:194)
  at android.view.View.measure (View.java:26207)
  at android.widget.LinearLayout.measureHorizontal (LinearLayout.java:1185)
  at android.widget.LinearLayout.onMeasure (LinearLayout.java:723)
  at android.view.View.measure (View.java:26207)
  at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:7020)
  at android.widget.FrameLayout.onMeasure (FrameLayout.java:194)
  at androidx.appcompat.widget.ContentFrameLayout.onMeasure (ContentFrameLayout.java:145)
  at android.view.View.measure (View.java:26207)
  at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:7020)
  at androidx.appcompat.widget.ActionBarOverlayLayout.onMeasure (ActionBarOverlayLayout.java:496)
  at android.view.View.measure (View.java:26207)
  at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:7020)
  at android.widget.FrameLayout.onMeasure (FrameLayout.java:194)
  at android.view.View.measure (View.java:26207)
  at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:7020)
  at android.widget.LinearLayout.measureChildBeforeLayout (LinearLayout.java:1552)
  at android.widget.LinearLayout.measureVertical (LinearLayout.java:842)
  at android.widget.LinearLayout.onMeasure (LinearLayout.java:721)
  at android.view.View.measure (View.java:26207)
  at android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:7020)
  at android.widget.FrameLayout.onMeasure (FrameLayout.java:194)
  at com.android.internal.policy.DecorView.onMeasure (DecorView.java:820)
  at android.view.View.measure (View.java:26207)
  at android.view.ViewRootImpl.performMeasure (ViewRootImpl.java:3770)
  at android.view.ViewRootImpl.measureHierarchy (ViewRootImpl.java:2544)
  at android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:2823)
  at android.view.ViewRootImpl.doTraversal (ViewRootImpl.java:2259)
  at android.view.ViewRootImpl$TraversalRunnable.run (ViewRootImpl.java:8961)
  at android.view.Choreographer$CallbackRecord.run (Choreographer.java:1142)
  at android.view.Choreographer.doCallbacks (Choreographer.java:946)
  at android.view.Choreographer.doFrame (Choreographer.java:875)
  at android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:1127)
  at android.os.Handler.handleCallback (Handler.java:938)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at android.os.Looper.loopOnce (Looper.java:210)
  at android.os.Looper.loop (Looper.java:299)
  at android.app.ActivityThread.main (ActivityThread.java:8087)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:556)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1045)

APK

From app: https://github.com/GroupeMINASTE/OCaml (available on the store at https://play.google.com/store/apps/details?id=me.nathanfallet.ocaml)

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had activity in the last 20 days. It will be closed if no further activity occurs within the next seven days. Thank you for your contributions.

nathanfallet commented 2 years ago

The issue is still happening

prathimode commented 2 years ago

This issue is due that a GL variable is getting updated in OnMeasure (which is running on the main thread) and onDraw( which is getting called on the GLRenderer Thread) Race condition for updating this variable is causing this issue. In my case I was getting this crash when I was doing the resizing of the GLSurfaceView. 1 out of 3 time doing resizing it is hitting this window. And was getting this crash.

java.nio.BufferOverflowException at java.nio.Buffer.nextPutIndex(Buffer.java:536) at java.nio.ByteBufferAsFloatBuffer.put(ByteBufferAsFloatBuffer.java:109) at com.otaliastudios.opengl.draw.GlRect.setRect(GlRect.kt:63) at com.otaliastudios.opengl.draw.GlRect.setRect(GlRect.kt:47) at com.otaliastudios.zoom.ZoomSurfaceView.onContentOrContainerSizeChanged(ZoomSurfaceView.kt:238) at com.otaliastudios.zoom.ZoomSurfaceView.onMeasure(ZoomSurfaceView.kt:215) at android.view.View.measure(View.java:27129) at androidx.constraintlayout.widget.ConstraintLayout$Measurer.measure(ConstraintLayout.java:811)

    The variable which is causing this is :
    ` glTextureRect.setRect(rect)` -> it is getting modified in onContentOrContainerSizeChanged() and also in the onDraw.

    One solution that comes to my mind is to thread safe this variable. if writer of this lib can make this change, it will be very much beneficial.