"IllegalArgumentException locking surface" when calling DoEvents

kcorey

Member
Licensed User
Longtime User
Hi All,

I found something that drove me mad for a day or so...

In my code, I am using the Animation library 1.02. I couldn't see an effect I was hoping to see on the Samsung Galaxy Tab 2 10 (Android 4.0.4)

I thought this might be caused by a runaway process...so I put a 'DoEvents' in my code, assuming that it if there were no messages it would effectively be ignored.

I happened to try the code on my Nexus 7 (Android 4.1.1) where it worked fine...but the program would seemingly halt on the Samsung.

Turns out it was an interesting exception (pasted at the bottom).

In looking at the generated java file com.flippinbits.milestones.main, line 3490, I see "DoEvents".

Is this a bug, or did I use DoEvents wrong?

-Ken
----------------------------------
E/SurfaceTextureClient(15563): Surface::lock failed, already locked
E/ViewRootImpl(15563): IllegalArgumentException locking surface
E/ViewRootImpl(15563): java.lang.IllegalArgumentException
E/ViewRootImpl(15563): at android.view.Surface.lockCanvasNative(Native Method)
E/ViewRootImpl(15563): at android.view.Surface.lockCanvas(Surface.java:76)
E/ViewRootImpl(15563): at android.view.ViewRootImpl.draw(ViewRootImpl.java:2004)
E/ViewRootImpl(15563): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1693)
E/ViewRootImpl(15563): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2505)
E/ViewRootImpl(15563): at android.os.Handler.dispatchMessage(Handler.java:99)
E/ViewRootImpl(15563): at anywheresoftware.b4a.Msgbox.waitForMessage(Msgbox.java:211)
E/ViewRootImpl(15563): at anywheresoftware.b4a.Msgbox.waitForMessage(Msgbox.java:180)
E/ViewRootImpl(15563): at anywheresoftware.b4a.keywords.Common.DoEvents(Common.java:367)
E/ViewRootImpl(15563): at com.flippinbits.milestones.main._setcard(main.java:3490)
E/ViewRootImpl(15563): at com.flippinbits.milestones.main._setgo_animationend(main.java:3528)
E/ViewRootImpl(15563): at java.lang.reflect.Method.invokeNative(Native Method)
E/ViewRootImpl(15563): at java.lang.reflect.Method.invoke(Method.java:511)
E/ViewRootImpl(15563): at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
E/ViewRootImpl(15563): at anywheresoftware.b4a.BA.raiseEvent2(BA.java:158)
E/ViewRootImpl(15563): at anywheresoftware.b4a.BA.raiseEvent(BA.java:154)
E/ViewRootImpl(15563): at anywheresoftware.b4a.objects.AnimationWrapper$1.onAnimationEnd(AnimationWrapper.java:104)
E/ViewRootImpl(15563): at android.view.animation.Animation.getTransformation(Animation.java:843)
E/ViewRootImpl(15563): at android.view.animation.Animation.getTransformation(Animation.java:887)
E/ViewRootImpl(15563): at android.view.ViewGroup.drawChild(ViewGroup.java:2668)
E/ViewRootImpl(15563): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2500)
E/ViewRootImpl(15563): at android.view.View.draw(View.java:11033)
E/ViewRootImpl(15563): at android.view.ViewGroup.drawChild(ViewGroup.java:2898)
E/ViewRootImpl(15563): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2500)
E/ViewRootImpl(15563): at android.view.ViewGroup.drawChild(ViewGroup.java:2896)
E/ViewRootImpl(15563): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2500)
E/ViewRootImpl(15563): at android.view.ViewGroup.drawChild(ViewGroup.java:2896)
E/ViewRootImpl(15563): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2500)
E/ViewRootImpl(15563): at android.view.View.draw(View.java:11033)
E/ViewRootImpl(15563): at android.widget.FrameLayout.draw(FrameLayout.java:450)
E/ViewRootImpl(15563): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2274)
E/ViewRootImpl(15563): at android.view.ViewRootImpl.draw(ViewRootImpl.java:2087)
E/ViewRootImpl(15563): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1693)
E/ViewRootImpl(15563): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2505)
E/ViewRootImpl(15563): at android.os.Handler.dispatchMessage(Handler.java:99)
E/ViewRootImpl(15563): at android.os.Looper.loop(Looper.java:137)
E/ViewRootImpl(15563): at android.app.ActivityThread.main(ActivityThread.java:4514)
E/ViewRootImpl(15563): at java.lang.reflect.Method.invokeNative(Native Method)
E/ViewRootImpl(15563): at java.lang.reflect.Method.invoke(Method.java:511)
E/ViewRootImpl(15563): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
E/ViewRootImpl(15563): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
E/ViewRootImpl(15563): at dalvik.system.NativeStart.main(Native Method)
 

kcorey

Member
Licensed User
Longtime User
The code in question is this simple:

B4X:
Sub setcard(idx As Int, cardid As String)
   Log("setCard "&idx&","&cardid)
   
   If cardid="" Then
      CardViews(idx).Bitmap = cardpics(19)
   Else
      CardViews(idx).Bitmap = cardpics(cardnums.Get(cardid))
   End If
   
   CardViews(idx).Invalidate
   
   DoEvents
   
   tableau(idx) = cardid
End Sub

The variables are declared like this:

B4X:
Sub Process_Globals
   Dim tableau(21) As String
End Sub

Sub Globals
   Dim C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12, C13, C14, C15, C16, C17, C18, C19, C20 As ImageView
   Dim CardViews() As ImageView
   Dim cardpics(20) As Bitmap
End Sub

By the time this code is called, the app is well and truly established and running, and all bitmaps are loaded.

Any ideas?

-Ken
 
Upvote 0

kcorey

Member
Licensed User
Longtime User
Oh! I get the idea.

I can't find documentation on callsubdelayed...but this seems to work:

CallSubDelayed(Me,"subname")

Is that the idea?

-Ken
 
Upvote 0
Top