return value from AAudio_createStreamBuilder on sample code
Closed this issue · 2 comments
On the sample code, when creating a stream, the following is done:
aaudio_result_t result = AAudio_createStreamBuilder(&builder);
if (result != AAUDIO_OK && !builder) {
LOGE("Error creating stream builder: %s", AAudio_convertResultToText(result));
}
Does that means that the return could be an error and still builder have a valid address? Or the result could be AAUDIO_OK and builder be a null pointer?
At first I didn't think much of it. It just seemed a double check. But the more I look at this it seems wrong. Neither case should happen right?
I would either: (a) check for an error, (b) check for address of builder, or (c) use an || instead of && in the if.
Or: this is code is ok and I'm missing something, and having an error and no pointer could be the expected behaviour in a case. Then it would be great to see that case in the docs.
it is more like a bug: should "||" I believe
Good catch. It should be "||".
And checking (builder != nullptr) is redundant.
Checking the return value is required. The function will return a negative error if the allocation fails. We need to document that better in AAudio.