I believe I'm seeing 'bursts' of calls coming in from AsyncStreams->AsyncStreamsText, and a subsequent call appears to be overwriting the data buffer used by the _NewText sub. I think it happens when a longer string of input is following by a much smaller set (say 44 characters, then the next one has 1-3 characters).
I may be wrong, I've only been using B4A for a few weeks. But the first app I downloaded
source for suffered from this problem; it was the first B4A code I looked at. When I added a multiple text (string) buffer (in a circular queue), and changed the code to just fill the buffer then callsubdelayed to let the _NewText return ASAP, it cleaned up quite a bit. In fact, as long as my app didn't fail to service the stream it was okay. But if I hit a menu or something, or the phone had something 'else' (outside the app) 'run', the data would no longer be intact. That particular app is pretty rough and is monolithic. I've almost completely rewritten it using modern techniques, and added some interesting functionality. But to play with it you need a 'compatible' BT serial source (the IR-BLUE), or modify the code to accept whatever stream you have available.
When I looked into AsyncStreamsText, it looks like the same type of thing could occur. Not asking for help on this just yet, I should be able to work through this and report back if I find my hypothesis to be true and corrected by the code. If so I'll submit a post here with a new AST that uses a CircularQueue, and an AST that uses it to buffer the input.
Edit: what I didn't know at the time is that Modal Dialogs will block all events, and AsyncStreams responds after the unblock by delivering the message substring packets out of order for some reason.
Anyway, I expect to finish it up shortly and test it hard (I have a 'realtime' Parallax Prop driven project that runs a stream out through a BT port, and I can vary the rate etc.
I had read something the other day about CircularQueues for Single Supplier/Consumer w/o a Semaphore using an Atomic, and thought I'd ask whether B4A supported an atomic. I don't need it to complete my task.
This was the
article.