Crashes when dividing device enumerations into functions: Not sure whether it's me or whether I've found a bug. #740
-
Hi there, I'm writing an application that needs to provide the user with an option to change devices. I'm using the high-level engine, and can't seem to find a way to do this. I am aware of ma_engine_get_device and ma_device_get_context so I tried to fashion a higher level API that I could use. I experienced all kinds of odd behaviour, both when attempting to enumerate the devices, and/or when cleaning up the audio system. I then attempted to make some tests to see exactly what might be going on. I found that when I do this all in one function, it works fine. But when I split it down, that's when problems start occurring. And here is the test that likes to crash Debuggers and memory analysis tools aren't really giving me useful info - it's one of those when you try and put various tests through it changes. Since test 1 works without a hitch, I'm guessing it's something ridiculously obvious in my code but I'm just not seeing it, hence the reason I haven't reported as an issue. Also ma_device_get_context doesn't seem to be documented so wondered whether that's an internal function rather than part of the public API. Any guidance would be very much appreciated. Cheers. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
So with ma_device_info* devinfo;
ma_uint32 count;
ma_context_get_devices(ctx, &devinfo, &count, NULL, NULL); That's it. No need for your count, malloc, enumerate cycle. However, an important detail. The next time you call
|
Beta Was this translation helpful? Give feedback.
-
Thanks David, I had an idea it'd be something dead simple like that. I'm guessing it's in the docs that ma_get_device_info manages the memory for you but for some reason I didn't catch that. |
Beta Was this translation helpful? Give feedback.
So with
ma_context_get_devices()
you do not need to allocate your own buffers. That's all managed internally for you. So the process you're using of counting first, then allocating, the enumerating again is incorrect. You can simplify the whole thing by simply doing this once:That's it. No need for your count, malloc, enumerate cycle.
However, an important detail. The next time you call
ma_context_get_devices()
, or when you you uninitialize your context, the devinfo buffer will be deleted, so watch out for that.ma_device_get_context()
is a fully supported public API. It's just a simple g…