kcat / alure

Alure is a utility library for OpenAL, providing a C++ API and managing common tasks that include file loading, caching, and streaming
zlib License
70 stars 20 forks source link

How to safely use Context::precacheBuffersAsync? #42

Closed McSinyx closed 4 years ago

McSinyx commented 4 years ago

As encountered in McSinyx/palace#59, we are struggling to find a way keep the data whose array and string views are passed to Context::precacheBuffersAsync. The primary issue is that it is quite difficult to ensure that the cached version of original strings and their containers and the views reference to the same data.

I have yet to find precacheBuffersAsync used anywhere on GitHHub, but suggest that the method should receive the actual data, e.g. Vector<String> instead, since the size of the argument is usually not significant. If this is possible, this would simplify the usage a lot.

kcat commented 4 years ago

I'm not sure I see the problem. If you have a Vector<String> names that holds the names (or otherwise have the strings available for the duration of the call), you can create a Vector<StringView> alure_names that holds views to those strings and can pass it in as an ArrayView<StringView> to Context::precacheBuffersAsync. Once the function returns, you can safely get rid of the views and the array/string data. The context will have the names copied to do the loading.

McSinyx commented 4 years ago

Thank you for the headsup. I was so certain that the segfault is because of precacheBuffersAsync that I didn't even run gdb. Anyway the bug is on ourside, in the handling of bufferLoading message (due to an unsolved problem with Python GIL).

I'm so sorry for the misleading issue. Stay safe!