Fix undefined behavior with --debug-xr
Mistake in cb578ca104
. 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.
This commit is contained in:
parent
77e4905b17
commit
c074943dfd
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue