Bug? Unusual behaviour of B4A 7.80

hatzisn

Expert
Licensed User
Longtime User
Good evening,

I noticed some unexpected behaviour in B4A 7.80. There are two issues I noticed. Here they are:

First Issue:

Watch this code:
B4X:
Sub Recursive(variable as string)
   line 1
   line 2
   if some_condition = true then
      Recursive(variable2 as string)
   End if
   Sleep(0)
   line 3
   line 4
End Sub

Let's say we run this code recursive. In the first pass we send the variable="var1". The condition = true and it calls the recursive with variable2="var2". We get in the sub for the second pass and this time the some_condition = false and it continues to sleep(0). The code execution will continue in the first pass and then in the second. It's like having multiple threads that intermix. If we remove the Sleep(0) everything works linearly. That was tested in an Android 7.0 Emulator.

Second Issue:

Let's suppose we add a class named Book.

Watch this code:
B4X:
Private Sub Class_Globals
   Type BookInfo(Title as String, _
           Writer as String, _
           Pages as Int, _
           ISBN as String)
   Dim BI As BookInfo
   Dim pnl as Panel
End Sub

If we try to access BI from another module. The BI variable is not appearing. If we now transform the code as follows (adding some lines between the BI Variable and the type and the Panel), the BI variable shows in the intelligence of the class.

B4X:
Private Sub Class_Globals
   Type BookInfo(Title as String, _
             Writer as String, _
             Pages as Int, _
             ISBN as String)

   Dim BI As BookInfo

   Dim pnl as Panel
End Sub


Thanks for taking the time to read this.
 
Last edited:

hatzisn

Expert
Licensed User
Longtime User
Hi Erel. Actually I do not want to upload the project because it is an ordered project from a client.
Can't you reproduce the errors I mentioned.
 

hatzisn

Expert
Licensed User
Longtime User
I created a project. I cannot reproduce the second error. But download and watch:
B4A Bug Project

Run it first without doing anything else and watch the logs. Add also a break point in the
Get_All_SubCategories first line and try to run it with F8. Finally remove the break point
and comment out the sleep(0) and rerun.
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
It doesn't look like a bug. I recommend you to see the resumable subs video as it explains the code flow: https://www.b4x.com/etp.html

If you want to wait for the child sub to complete then you need to change the code to:
B4X:
Sub Get_All_SubCategories(iLevel As Int) As ResumableSub
   If iLevel = 3 Then Return 0
   For i = 1 To 30
       Log(iLevel & "-" & i)
       Wait For (Get_All_SubCategories(iLevel+1)) Complete (unused As Int)
       Sleep(0)
   Next
   Return 0
End Sub
 

hatzisn

Expert
Licensed User
Longtime User
Thanks Erel. I didn't know about it. I saw the video and tried to download the source but
when I pressed the download source link it started downloading the video and not the source.
Can you please post the source code of the video here?
 
Last edited:

hatzisn

Expert
Licensed User
Longtime User
Thanks DonManfred...
 
Top