Android Question callsubdelay works on legacy not on rapid

SteveTerrell

Active Member
Licensed User
Longtime User
Hi,
I have a class, used to handle my state machine software. The class has, amongst others, these two methods

B4X:
Public Sub AddToEventAndDataQueue(event As Int, data As Object)
Dim newMsg As eventAndData
    newMsg.Initialize
    newMsg.event = event
    newMsg.data = data
    eventAndDataQueue.Add(newMsg)    ' my work queue (a list)
    CallSubDelayed(Me, "RunStateMachine")
End Sub

RunStateMachine is also in the class

B4X:
Sub RunStateMachine
    Do While eventAndDataQueue.Size > 0
        Dim newMsg As eventAndData = eventAndDataQueue.Get(0)
        eventAndDataQueue.RemoveAt(0)
        CallSub3(Module, StateCode, newMsg.event, newMsg.data)
    Loop
End Sub


Module and StateCode are setup when the class is initialised in activity_create, i.e.
pMainScreenButtonManager.Initialize( Me, "MainScreenButtonManagerCode")

Me is saved in class variable Module, the sub name (MainScreenButtonManagerCode) is saved in the class variable StateCode

Several instances of the class are created, mostly in activity_create and all with different subs named in the initialize call.
i.e.
pTopLevelManager.Initialize( Me, "TopLevelCode")

The classes send "messages" to each other using AddToEventAndDataQueue.

i.e. in pTopLevelManager a "message" is sent to the button manager.

pMainScreenButtonManager.AddToEventAndDataQueue(SHOW_START_BUTTON,Null)

The idea being that the button manager code will run when the top level manage sub returns. Several "messages" may be sent in one call of the originating sub. Usually the originating sub (such as top level manager) was its self run from a "RunStateMachine" sub call after it received a button click "message"





This works some of the time in Rapid Debugger and all of the time in Legacy Debugger.

In Rapid Debugger the CallSubDelayed will usually fail at a certain point in the program run (having worked when used earlier). In the Legacy Debugger it works every time.

Fail means the CallSubDelayed code line executes, there is nothing in filtered or unfiltered logs to suggest a problem, but the RunStateMachine sub is not executed.

Occasionally but not consistently a break point before the "AddTo.." call will result in the delayed call working but then on the next run (without any program changes) it will fail again.

Should i be concerned about my code or is it likely to be some sort of rapid debugger issue?

Steve
 

SteveTerrell

Active Member
Licensed User
Longtime User
It sounds like a debugger issue. If this issue is reproducible then I would be happy to check your project.

It was mostly reproducible (95% perhaps).

Thanks for the offer. The project is rather large now and needs a bit of "setting up" to work without my BLE hardware. If i can create a smaller version i will.

For now i have kind of created my own callsubdelayed (at least the run in sequence characteristics) by saving the messages generated by each state machine in its own list then passing them on to other state machines after the loop in runstatemachine. The target for the message is then run using callsub. This avoids the problem of calls to other state machines in the middle of the state machine code.

Steve
 
Upvote 0
Top