diff options
author | Julian Eisel <julian@blender.org> | 2020-08-14 17:38:45 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2020-08-14 18:03:10 +0300 |
commit | c074943dfd914fafd25f59cd43e26b4e8ac499f0 (patch) | |
tree | 66e4a6d06738b27bf410c9803041f17a41ed28dc /intern/ghost | |
parent | 77e4905b171a57bfe6e4e92864747534cdba9f53 (diff) |
Fix undefined behavior with --debug-xr
Mistake in cb578ca1048d3. Before that, the extension vector was static,
to make sure the extension name strings wouldn't get destructed when
leaving the function. I didn't think that was an issue and couldn't
recreate one, because until the previous commit we wouldn't actually
add any extensions to the vector on Windows (the system I tested
with).
Use C++17's `std::string_view` now, which avoids the string copies
`std::string` creates for itself and thus its destruction when leaving
the local scope.
Diffstat (limited to 'intern/ghost')
-rw-r--r-- | intern/ghost/intern/GHOST_XrContext.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/intern/ghost/intern/GHOST_XrContext.cpp b/intern/ghost/intern/GHOST_XrContext.cpp index 0d8d42a72f7..3dbf539f0c7 100644 --- a/intern/ghost/intern/GHOST_XrContext.cpp +++ b/intern/ghost/intern/GHOST_XrContext.cpp @@ -23,6 +23,7 @@ #include <cassert> #include <sstream> #include <string> +#include <string_view> #include "GHOST_Types.h" #include "GHOST_XrException.h" @@ -348,7 +349,7 @@ static bool openxr_layer_is_available(const std::vector<XrApiLayerProperties> la } static bool openxr_extension_is_available(const std::vector<XrExtensionProperties> extensions_info, - const std::string &extension_name) + const std::string_view &extension_name) { for (const XrExtensionProperties &ext_info : extensions_info) { if (ext_info.extensionName == extension_name) { @@ -405,7 +406,7 @@ void GHOST_XrContext::getExtensionsToEnable( const std::vector<GHOST_TXrGraphicsBinding> &graphics_binding_types, std::vector<const char *> &r_ext_names) { - std::vector<std::string> try_ext; + std::vector<std::string_view> try_ext; /* Try enabling debug extension. */ if (isDebugMode()) { @@ -422,9 +423,9 @@ void GHOST_XrContext::getExtensionsToEnable( r_ext_names.push_back(gpu_binding); } - for (const std::string &ext : try_ext) { + for (const std::string_view &ext : try_ext) { if (openxr_extension_is_available(m_oxr->extensions, ext)) { - r_ext_names.push_back(ext.c_str()); + r_ext_names.push_back(ext.data()); } } } |