-
-
Notifications
You must be signed in to change notification settings - Fork 420
Implement ALC.getStringList() #1988
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 8.4.0-dev
Are you sure you want to change the base?
Conversation
Yeah, it's a bit ugly but I had to do that since Maybe the check could be done on the C++ side but ngl my C(++) is a bit rusty.
This could've be done as well but I opted in for a seperate method because I wanted to do as much as possible on the C++ side and other OpenAL bindings seem to do something similar. |
| while (*result != '\0') { | ||
|
|
||
| int length = strlen (result) + 1; | ||
| char* _result = (char*)malloc (length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we need a free() call to go with this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we need a
free()call to go with this?
Maybe hl_alloc_bytes would be safer instead of malloc, since we can't call free() immediately?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a free() call. I've tested it a bit and it seems to work fine, but I will say again that my C(++) is a bit rusty so please do tell if I've overlooked something!!
I will also note that there's other malloc() calls in the OpenAL bindings that do not have a corresponding free() call. Perhaps this should also be handled in a seperate issue?
lime/project/src/media/openal/OpenALBindings.cpp
Lines 2209 to 2217 in 36d7953
| HL_PRIM vbyte* HL_NAME(hl_al_get_string) (int param) { | |
| const char* result = alGetString (param); | |
| int length = strlen (result); | |
| char* _result = (char*)malloc (length + 1); | |
| strcpy (_result, result); | |
| return (vbyte*)_result; | |
| } |
lime/project/src/media/openal/OpenALBindings.cpp
Lines 3389 to 3398 in 36d7953
| HL_PRIM vbyte* HL_NAME(hl_alc_get_string) (HL_CFFIPointer* device, int param) { | |
| ALCdevice* alcDevice = device ? (ALCdevice*)device->ptr : 0; | |
| const char* result = alcGetString (alcDevice, param); | |
| int length = strlen (result); | |
| char* _result = (char*)malloc (length + 1); | |
| strcpy (_result, result); | |
| return (vbyte*)_result; | |
| } |


Fixes #1986
There are certain OpenAL parameters, meant to be passed into
ALC.getString(), that return a list of strings. For example,ALC_ALL_DEVICES_SPECIFIERto get the names of available playback audio devices orALC_CAPTURE_DEVICE_SPECIFIERto get the names of available capture devices.ALC.getString()assumes that the result will always be a standard C string with a single NULL character at the end, but this is not the case when passing the params mentioned above:This PR introduces the
ALC.getStringList(device, param)method which handles these lists properly and returns them as anArray<String>. If list handling is unnecessary for the param provided, the result will simply be[ALC.getString(device, param)]