B4J Question Help with async error


Active Member
Somehow I screwed something up. After initializing the async stream for serial port communications (see code below) the debugger immediately throws the following fatal error:

Program started.
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc

when it executes the astream.Initialize

starting an async serial port stream:
    sp.SetParams(sp.BAUDRATE_9600, sp.DATABITS_8, sp.STOPBITS_1, sp.PARITY_SPACE)
    astream.Initialize(sp.GetInputStream, sp.GetOutputStream, "astream")

I do not know why this is all of the sudden happening? It was working. Is there a method to debug this?
From some generic web searching, the error seems to be related to memory allocation?
Don't know why this has occurred.

On my laptop, I get openjdk error, and on the raspberry pi I am running this on I get the above error.


Active Member
You are right of course, sorry about the grammar. The problem generated was my stupid coding problem. I assumed the serial port I was trying to open was at the "Get(0)" and was not doing a proper search through the list to find the proper name. I was lucky, that the system mapped the serial port to "Get(0)" and not lower in the "Listports", well my luck ran out. I put a proper search in the code, and it turns out it is now at "Get(2)". Now its working fine. My dumb mistake. I should not take things for granted.
Upvote 0