[Bf-blender-cvs] [c074943dfd9] blender-v2.90-release: Fix undefined behavior with --debug-xr
Julian Eisel
noreply at git.blender.org
Fri Aug 14 17:11:31 CEST 2020
Commit: c074943dfd914fafd25f59cd43e26b4e8ac499f0
Author: Julian Eisel
Date: Fri Aug 14 16:38:45 2020 +0200
Branches: blender-v2.90-release
https://developer.blender.org/rBc074943dfd914fafd25f59cd43e26b4e8ac499f0
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.
===================================================================
M intern/ghost/intern/GHOST_XrContext.cpp
===================================================================
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());
}
}
}
More information about the Bf-blender-cvs
mailing list