From 02e54103813f90eac34530de95c868251df01b9b Mon Sep 17 00:00:00 2001 From: jp9000 Date: Sun, 13 Mar 2022 07:04:11 -0700 Subject: [PATCH] UI: Fix audio ids not being stored properly Audio ids were being stored in a map with const char pointers, thus they were destroyed when call_once finished. To fix this, store std::strings instead. --- UI/audio-encoders.cpp | 10 +++++----- UI/audio-encoders.hpp | 2 +- UI/window-basic-settings.cpp | 5 +++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/UI/audio-encoders.cpp b/UI/audio-encoders.cpp index 86441ec27..4423cd17e 100644 --- a/UI/audio-encoders.cpp +++ b/UI/audio-encoders.cpp @@ -18,12 +18,12 @@ static const char *NullToEmpty(const char *str) return str ? str : ""; } -static const char *EncoderName(const char *id) +static const char *EncoderName(const std::string &id) { - return NullToEmpty(obs_encoder_get_display_name(id)); + return NullToEmpty(obs_encoder_get_display_name(id.c_str())); } -static map bitrateMap; +static map bitrateMap; static void HandleIntProperty(obs_property_t *prop, const char *id) { @@ -199,7 +199,7 @@ static void PopulateBitrateMap() }); } -const map &GetAACEncoderBitrateMap() +const map &GetAACEncoderBitrateMap() { PopulateBitrateMap(); return bitrateMap; @@ -211,7 +211,7 @@ const char *GetAACEncoderForBitrate(int bitrate) auto res = map_.find(bitrate); if (res == end(map_)) return NULL; - return res->second; + return res->second.c_str(); } #define INVALID_BITRATE 10000 diff --git a/UI/audio-encoders.hpp b/UI/audio-encoders.hpp index e1aba6530..3bb0596e6 100644 --- a/UI/audio-encoders.hpp +++ b/UI/audio-encoders.hpp @@ -4,6 +4,6 @@ #include -const std::map &GetAACEncoderBitrateMap(); +const std::map &GetAACEncoderBitrateMap(); const char *GetAACEncoderForBitrate(int bitrate); int FindClosestAvailableAACBitrate(int bitrate); diff --git a/UI/window-basic-settings.cpp b/UI/window-basic-settings.cpp index 8486b3bf6..6210bba8e 100644 --- a/UI/window-basic-settings.cpp +++ b/UI/window-basic-settings.cpp @@ -277,8 +277,9 @@ static void PopulateAACBitrates(initializer_list boxes) vector> pairs; for (auto &entry : bitrateMap) - pairs.emplace_back(QString::number(entry.first), - obs_encoder_get_display_name(entry.second)); + pairs.emplace_back( + QString::number(entry.first), + obs_encoder_get_display_name(entry.second.c_str())); for (auto box : boxes) { QString currentText = box->currentText();