Bug: Touch Action Up recycled twice

Woinowski

Active Member
Licensed User
Longtime User
Hi,

I get this stacktrace from Google Play. Cannot reproduce it myself. And the trace contains nothing from my code. So it might be a B4A bug. Or does somebody know thid and there is a fix?
java.lang.RuntimeException: MotionEvent { action=ACTION_UP, id[0]=0, x[0]=876.2523, y[0]=700.89905, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=3186384, downTime=3186267, deviceId=4, source=0x1002 } recycled twice! at android.view.MotionEvent.recycle(MotionEvent.java:1673) at android.view.ViewRootImpl.finishMotionEvent(ViewRootImpl.java:2904) at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:2895) at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2466) at android.view.ViewRootImpl.processInputEvents(ViewRootImpl.java:845) at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2475) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4424) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) at dalvik.system.NativeStart.main(Native Method)
 
Last edited:

agraham

Expert
Licensed User
Longtime User
Last edited:

Woinowski

Active Member
Licensed User
Longtime User
you are right

Removed the "code" brackets, so that it's better readable. It is a "recycled twice error". Don't know more than that stack trace.

Since I cannot remove doevents (progressdialog required), i will try to put it in try/catch and see if it disappears then.

You don't give the actual error message but it looks ike it might be a "recycled twice!" error.

http://www.b4x.com/forum/basic4android-updates-questions/16584-can-some-one-help-me-error-code.html
On this occasion removing DoEvents "cured" the problem.

http://www.b4x.com/forum/basic4android-updates-questions/17450-breakpoints-crash-ics.html
This is repeatable under the debugger - I hope Erel is looking at it.
 

Woinowski

Active Member
Licensed User
Longtime User
What seemed to help

Two measures:
  1. Put every "DoEvents" into a try/catch block
  2. Return True in every touch event method

I have now new bug reports in Google Play since then. Maybe that fixed it. Either one of the two, or both.

Maybe somebody with more details about the B4A implementation might tell which is the crucial part of the solution.
 
D

Deleted member 103

Guest
Hi,

I have the same problem in my game "Solitario" (ICS Android version 4.0.3).

I hope Erel can resolve the problem as quickly as possible.

Ciao,
Filippo
 
D

Deleted member 103

Guest
Hi Woinowski,

I used your tip but it still does not work.
  1. Put every "DoEvents" into a try/catch block
  2. Return True in every touch event method
Here's my error message:
HTML:
nativeDestroy view: 0x283e58
nativeDestroy view: 0xf2ed0
Displayed fg.Solitario_free/.m4karten: +6s538ms
GC_CONCURRENT freed 353K, 4% free 16826K/17351K, paused 7ms+9ms
Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@416057a8
Launch timeout has expired, giving up wake lock!
Activity idle timeout for ActivityRecord{417e5320 fg.Solitario_free/.m4karten}
** Activity (m4karten) Resume **
Received ad url: <"url": "http://googleads.g.doubleclick.net:80/mads/gma?preqs=1&u_sd=2&slotname=a14e8f77524dde8&u_w=360&msid=fg.Solitario_free&cap=m%2Ca&js=afma-sdk-a-v4.1.0&isu=B3EEABB8EE11C2BE770B684D95219ECB&format=320x50_mb&net=ed&app_name=7.android.fg.Solitario_free&hl=en&u_h=592&u_audio=4&u_so=p&adtest=on&output=html&region=mobile_app&u_tz=0&ex=1&client_sdk=1&askip=1&caps=sdkAdmobApiForAds&jsv=23", "afmaNotifyDt": "null">
java.lang.Throwable: Warning: A WebView method was called on thread 'AsyncTask #4'. All WebView methods must be called on the UI thread. Future versions of WebView may not support use on other threads.
   at android.webkit.WebView.checkThread(WebView.java:9468)
   at android.webkit.WebView.loadDataWithBaseURL(WebView.java:2186)
   at c.a(Unknown Source)
   at c.doInBackground(Unknown Source)
   at android.os.AsyncTask$2.call(AsyncTask.java:264)
   at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
   at java.util.concurrent.FutureTask.run(FutureTask.java:137)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
   at java.lang.Thread.run(Thread.java:856)
onReceiveAd()
bufferCount (4) is too small and increased to 12
Activity.ACTION_DOWN
Activity.ACTION_MOVE
Activity.ACTION_MOVE
Activity.ACTION_MOVE
Activity.ACTION_MOVE
Activity.ACTION_MOVE
Activity.ACTION_MOVE
Activity.ACTION_UP
Activity.ACTION_UP

Shutting down VM
threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
java.lang.RuntimeException: MotionEvent { action=ACTION_UP, id[0]=0, x[0]=248.0, y[0]=401.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=7128936, downTime=7127386, deviceId=0, source=0x1002 } recycled twice!
   at android.view.MotionEvent.recycle(MotionEvent.java:1659)
   at android.view.ViewRootImpl.finishMotionEvent(ViewRootImpl.java:2904)
   at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:2895)
   at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2466)
   at android.view.ViewRootImpl.processInputEvents(ViewRootImpl.java:845)
   at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2475)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at android.os.Looper.loop(Looper.java:137)
   at android.app.ActivityThread.main(ActivityThread.java:4424)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
   at dalvik.system.NativeStart.main(Native Method)
FATAL EXCEPTION: main
java.lang.RuntimeException: MotionEvent { action=ACTION_UP, id[0]=0, x[0]=248.0, y[0]=401.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=7128936, downTime=7127386, deviceId=0, source=0x1002 } recycled twice!
   at android.view.MotionEvent.recycle(MotionEvent.java:1659)
   at android.view.ViewRootImpl.finishMotionEvent(ViewRootImpl.java:2904)
   at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:2895)
   at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2466)
   at android.view.ViewRootImpl.processInputEvents(ViewRootImpl.java:845)
   at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2475)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at android.os.Looper.loop(Looper.java:137)
   at android.app.ActivityThread.main(ActivityThread.java:4424)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
   at dalvik.system.NativeStart.main(Native Method)
  Force finishing activity fg.Solitario_free/.m4karten
Failure taking screenshot for (240x394) to layer 21015
Jit: resizing JitTable from 8192 to 16384
Activity pause timeout for ActivityRecord{417e5320 fg.Solitario_free/.m4karten}
Launch timeout has expired, giving up wake lock!
Activity idle timeout for ActivityRecord{41799200 fg.Solitario_free/.main}
 

agraham

Expert
Licensed User
Longtime User
A WebView method was called on thread 'AsyncTask #4'. All WebView methods must be called on the UI thread. Future versions of WebView may not support use on other threads.
That is a different error. It is not a "recycled twice" problem. It looks like you are you accessing a WebView from an AsyncTask thread which is not allowed.
 
Last edited:
D

Deleted member 103

Guest
Hi agraham,

But it is exactly the same error message, you must read my report errors completely.
My emulator plunges from on these lines.
B4X:
Shutting down VM
threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
java.lang.RuntimeException: MotionEvent { action=ACTION_UP, id[0]=0, x[0]=248.0, y[0]=401.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=7128936, downTime=7127386, deviceId=0, source=0x1002 } recycled twice!
 

Woinowski

Active Member
Licensed User
Longtime User
how to reproduce the bug?

The try catch around DoEvents really did not help. I'd be happy to test the 1.92 beta, but I cannot reproduce the bug with my app.
 

Woinowski

Active Member
Licensed User
Longtime User
Understood it now and have a workaround

I understood now, why I could not reproduce the bug: Some other post mentions that it is only an issue with Android 4.0.3 :)

My workaround: In the touch event handling sub I just start a timer end the end the touch event handling.

The time ticks after the touch event has been finished and starts the real action. No worries with DoEvents within a touch event.

This works with B4A 1.9 already (besides I wonder if it is not a good practice anyhow, if you want to start long-running tasks from a touch event).
 

cheese

Member
Licensed User
Longtime User
I'm running v2.0.2 and I still get this "recycled twice" error. I am running Android 4.0.4.


B4X:
java.lang.RuntimeException: MotionEvent { action=ACTION_UP, id[0]=0, x[0]=419.3125, y[0]=573.21875, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=17038486, downTime=17038312, deviceId=9, source=0x1002 } recycled twice!
   at android.view.MotionEvent.recycle(MotionEvent.java:1659)
   at android.view.ViewRootImpl.finishMotionEvent(ViewRootImpl.java:2904)
   at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:2895)
   at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2466)
   at android.view.ViewRootImpl.processInputEvents(ViewRootImpl.java:845)
   at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2475)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at android.os.Looper.loop(Looper.java:137)
   at android.app.ActivityThread.main(ActivityThread.java:4575)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
   at dalvik.system.NativeStart.main(Native Method)
 

cheese

Member
Licensed User
Longtime User
Sorry for the delay in my response.

Here's the event code:

B4X:
Sub ListView3_ItemClick (Position As Int, Value As Object)
   Dim entry As Map
   If Position > -1 Then
      Dim r As List 
      r.Initialize 
      r.AddAll(Array As String("Remove Filter"))
      Dim ip As id
      m = ip.InputList1(r,"Choose an action")
      If m <= -1 Then
         Return
      Else If (r.get(m)="Remove Filter") Then
         Dim result As Int
         result = Msgbox2("Are you sure you want to remove this filter?","Remove Filter","Yes","No","",Null)

         If(result=DialogResponse.POSITIVE)Then
            DeleteCallFilter(Value)
         End If
      End If
   End If
End Sub

and here is the method which gets called:

B4X:
Sub DeleteCallFilter(filtering As String)
   jobURL = voipms.GetAPIBase(voipms.Base) & "method=delCallerIDFiltering"
   jobURL = jobURL & "&filtering="&filtering
   
   HttpUtils.CallbackActivity = "Main" 
   HttpUtils.CallbackJobDoneSub = "Done"
   urls.Put("DeleteCallFilter",jobURL)
    HttpUtils.Download("DeleteCallFilter", jobURL)
End Sub

and the subsequent log entry:

B4X:
Starting Job: DeleteCallFilter
java.lang.RuntimeException: MotionEvent { action=ACTION_UP, id[0]=0, x[0]=414.78125, y[0]=454.5, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=20987147, downTime=20987033, deviceId=9, source=0x1002 } recycled twice!
 

cheese

Member
Licensed User
Longtime User
Here's another example where I get the same exception... In this particular case there is no "DISA" string specified. The IF STATEMENT is true (Msgbox is displayed) and then the exception is thrown.

mnuDISACall is an Activity menu item.

B4X:
java.lang.RuntimeException: MotionEvent { action=ACTION_UP, id[0]=0, x[0]=145.25, y[0]=435.75, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=26468645, downTime=26468545, deviceId=9, source=0x1002 } recycled twice!
   at android.view.MotionEvent.recycle(MotionEvent.java:1659)
   at android.view.ViewRootImpl.finishMotionEvent(ViewRootImpl.java:2904)
   at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:2895)
   at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2466)
   at android.view.ViewRootImpl.processInputEvents(ViewRootImpl.java:845)
   at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2475)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at android.os.Looper.loop(Looper.java:137)
   at android.app.ActivityThread.main(ActivityThread.java:4575)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
   at dalvik.system.NativeStart.main(Native Method)

with the code:

B4X:
Sub mnuDISACall_click
   If (manager.GetString("disa")=="")Then
      Msgbox("Please go to the 'Settings' menu and specify your DISA calling string","Missing DISA String") 
   Else
      Dim i As Intent
      i.Initialize("android.intent.action.DIAL","tel:"&manager.GetString("disa"))
      StartActivity(i)
   End If
End Sub
 

cmweb

Active Member
Licensed User
Longtime User
Same here...

Getting the same error with B4A 2.02 on a Android 4.0.4 Device (Galaxy Note) when using an inputlist.

Error appears from time to time, not always.

My code:

B4X:
ergebnis = InputList(actionlist,"Select:",0)
   If ergebnis = 0 Then 
      identselect = Position
      StartActivity("edit")
   End If
   If ergebnis = 1 Then
      If freeversion = False Then
         identselect = ListView1.Size
         newitem = True
         StartActivity("edit")
      Else
         If ListView1.Size < 4 Then
            identselect = ListView1.Size
            newitem = True
            StartActivity("edit")
         Else
            Marketlink
         End If
      End If
   End If
   If ergebnis = 2 Then
      Msgbox("This feature is not yet implemented.","Attention!")
   End If

Best regards,

Carsten
 
Top