Android Question Problem with DoEvents on Android 4.4.2

luciano deri

Active Member
Licensed User
Longtime User
I was made a simple App that accept on edit text and in edittext_enterpressed write a db and show a table designed with scrollwiev.
B4X:
sub ET_EnterPressed
    if ET.Text = "" then
        return
    end if
    WriteDB
    ShowList
end sub 'Crash in this point
sub ShowList
    Dim PH As Int    : PH = 5%Y  
    ScrollView1.Panel.RemoveAllViews
  
    strquery = ("SELECT ..."'")
    dbCursor = Main.dbSql.ExecQuery(strquery)
    For i = 0 To dbCursor.RowCount - 1
        DoEvents
        dbCursor.position = i

        panel1.Initialize("PRow")
        ScrollView1.Panel.AddView(ps, 0, i * PH, 100%x, PH)
        panel1.LoadLayout("LayRow")

        ....
          
      
    Next
  
ScrollView1.Panel.Height = dbCursor.RowCount * PH
    dbCursor.Close
end sub
This code is ok in android 4.1.2, but in 4.4.2
is crashed without write anything on filtered log. Without filter i extract the position of log where the crash is done:
DCD OFF

Window spent 25225.9ms processing the last input event:

Fatal signal 11 (SIGSEGV) at 0x0000000c (code=1), thread 1685 (iscoapp.rilinve)

*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

Build fingerprint: 'samsung/matisseltexx/matisselte:4.4.2/KOT49H/T535XXU1ANK1:user/release-keys'

Revision: '3'

pid: 1685, tid: 1685, name: iscoapp.rilinve >>> it.multidatanet.siscoapp.rilinve <<<

signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0000000c

r0 00000000 r1 bef38a80 r2 bef390f3 r3 00000040

....

If comment DoEvent there isn't problems for every version. Why?
 
Last edited:

MarcoRome

Expert
Licensed User
Longtime User
Try this :
B4X:
 For i = 0 To dbCursor.RowCount - 1
           dbCursor.position = i

        panel1.Initialize("PRow")
        SVsinonimi.Panel.AddView(ps, 0, i * PH, 100%x, PH)
        panel1.LoadLayout("LayRow")

        ....
          
         DoEvents 
    Next
 
Upvote 0

luciano deri

Active Member
Licensed User
Longtime User
you are trying to add ps many times (in the loop).

I suppose you want to add a new ps each time, then you should declare it inside the loop.

If it should be Panel1... it's the same; Panel1 should be declared inside the loop.
The right metod is made a array of panel
ScrollView1.Panel.AddView(ps(i), 0, i * PH, 100%x, PH)
but the problem isen't here
 
Last edited:
Upvote 0

luciano deri

Active Member
Licensed User
Longtime User
Could give me an example? I use DoEvents every time i make long process of "for ... next" and i need show a ProgressDialogShow, without DoEvents the dialog not turn round...
 
Upvote 0

luciano deri

Active Member
Licensed User
Longtime User
B4X:
sub ShowList
    Dim PH As Int    : PH = 5%Y 
    ScrollView1.Panel.RemoveAllViews
 
    strquery = ("SELECT ..."'")
    dbCursor = Main.dbSql.ExecQuery(strquery)
    ProgressDialogShow("waith")
    For i = 0 To dbCursor.RowCount - 1
        DoEvents 
        dbCursor.position = i

        panel1.Initialize("PRow")
        ScrollView1.Panel.AddView(ps, 0, i * PH, 100%x, PH)
        panel1.LoadLayout("LayRow")

        ....
         
     
    Next
 
ScrollView1.Panel.Height = dbCursor.RowCount * PH
    dbCursor.Close
end sub
This the original code, i dont know how many row has table.
But with DoEvents only on samsung tab4 (Android 4.4.2) crash. Without is ok but with a lot of row the app appears blocked. So i thinked use ProgressDialogShow to wait, but only with DoEvents this turn round..
 
Upvote 0

luciano deri

Active Member
Licensed User
Longtime User
Same Error, but without DoEvents
Fatal signal 11 (SIGSEGV) at 0x0000000c (code=1), thread 1685 (iscoapp.rilinve)

*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

Build fingerprint: 'samsung/matisseltexx/matisselte:4.4.2/KOT49H/T535XXU1ANK1:user/release-keys'

Revision: '3'

pid: 1685, tid: 1685, name: iscoapp.rilinve >>> it.multidatanet.siscoapp.rilinve <<<

signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0000000c

r0 00000000 r1 bef38a80 r2 bef390f3 r3 00000040
....
Device Samsum TAB4, with older tablet i have no problem.
 
Last edited:
Upvote 0

luciano deri

Active Member
Licensed User
Longtime User
B4X:
Sub ETSinCod_EnterPressed
    btsalva_Click
End Sub ' here crash
Sub btsalva_Click
             If ETSinCod.Text <> "" Then
                  LeggiSinonimo
             End If
             ETSinCod.RequestFocus
End Sub
Sub LeggiSinonimo
    EsisteSin = True
    'verifica se il sinonimo è un codice articolo
    LeggiArticolo(ETSinCod.Text) 'make only a query to find  code in table
    If Not(NuovoArticolo) Then
      Msgbox("Codice sinonimo già utilizzato","Sinonimo non valido")  
      Return
    End If 
End Sub
I solved in this way, but this problem is becoming annoying, because the critical point is not where the program stops and the log does not say anything
B4X:
Sub LeggiSinonimo
    EsisteSin = True
        'verifica se il sinonimo è un codice articolo
    LeggiArticolo(ETSinCod.Text)
    If Not(NuovoArticolo) Then
      CallSubDelayed("","messaggio")
      Return
    End If 
End Sub
Sub messaggio
    Msgbox("Codice sinonimo già utilizzato","Sinonimo non valido")  
End Sub
 
Last edited:
Upvote 0

blong

Active Member
Licensed User
Longtime User
I have also had problems with DoEvents in 4.4. Was fine on all earlier versions of Android I had tested. In 4.4 I simply removed all of the calls to DoEvents and had a less appealing user experience... BUT it worked.

It just caused my application to exit at random times. Perhaps the CPU is so fast that it does items out of order. I agree that DoEvents is a dangerous thing to do but I concur with the reason you use it to give the USER some feedback that something is happening.
 
Upvote 0

Dave O

Well-Known Member
Licensed User
Longtime User
FYI, I've found that Android 6 devices (using the GenyMotion emulator at least, maybe for real too) seem to be more touchy about DoEvents than Android 4 or 5.

Whenever I encounter a crash that seems inexplicable, I now include DoEvents in my "usual suspects" list of things to check. :)
 
Upvote 0
Top