summaryrefslogtreecommitdiff
path: root/servers
diff options
context:
space:
mode:
authorEoin O'Neill <eoinoneill1991@gmail.com>2022-12-09 22:39:14 -0800
committerYuri Sizov <yuris@humnom.net>2023-04-26 14:51:00 +0200
commit5120afc236c9d6425bc77ea03c93a7a5d5169a08 (patch)
tree90a92166837b1e3b574a7e6626b937ac4474ba70 /servers
parent4b4556179e541ef100202a1270e678f3bcac7fb6 (diff)
Fix crash caused by invalid mix_rate assignment due to bogus
project settings. We'll default to a sensible value in the case that a user has somehow managed to modify the configuration file incorrectly. Closes 69819 (cherry picked from commit 5a08091168782a924cd3a23baf31c5cd4cd63906)
Diffstat (limited to 'servers')
-rw-r--r--servers/audio/audio_driver_dummy.cpp2
-rw-r--r--servers/audio_server.cpp14
-rw-r--r--servers/audio_server.h5
3 files changed, 19 insertions, 2 deletions
diff --git a/servers/audio/audio_driver_dummy.cpp b/servers/audio/audio_driver_dummy.cpp
index e6257d9260..1d11c01b9a 100644
--- a/servers/audio/audio_driver_dummy.cpp
+++ b/servers/audio/audio_driver_dummy.cpp
@@ -41,7 +41,7 @@ Error AudioDriverDummy::init() {
samples_in = nullptr;
if (mix_rate == -1) {
- mix_rate = GLOBAL_GET("audio/driver/mix_rate");
+ mix_rate = _get_configured_mix_rate();
}
channels = get_channels();
diff --git a/servers/audio_server.cpp b/servers/audio_server.cpp
index 0344bf322d..49991e41d3 100644
--- a/servers/audio_server.cpp
+++ b/servers/audio_server.cpp
@@ -115,6 +115,20 @@ void AudioDriver::input_buffer_write(int32_t sample) {
}
}
+int AudioDriver::_get_configured_mix_rate() {
+ StringName audio_driver_setting = "audio/driver/mix_rate";
+ int mix_rate = GLOBAL_GET(audio_driver_setting);
+
+ // In the case of invalid mix rate, let's default to a sensible value..
+ if (mix_rate <= 0) {
+ WARN_PRINT(vformat("Invalid mix rate of %d, consider reassigning setting \'%s\'. \nDefaulting mix rate to value %d.",
+ mix_rate, audio_driver_setting, AudioDriverManager::DEFAULT_MIX_RATE));
+ mix_rate = AudioDriverManager::DEFAULT_MIX_RATE;
+ }
+
+ return mix_rate;
+}
+
AudioDriver::SpeakerMode AudioDriver::get_speaker_mode_by_total_channels(int p_channels) const {
switch (p_channels) {
case 4:
diff --git a/servers/audio_server.h b/servers/audio_server.h
index 155beb2000..6585043f63 100644
--- a/servers/audio_server.h
+++ b/servers/audio_server.h
@@ -66,6 +66,8 @@ protected:
void input_buffer_init(int driver_buffer_frames);
void input_buffer_write(int32_t sample);
+ int _get_configured_mix_rate();
+
#ifdef DEBUG_ENABLED
_FORCE_INLINE_ void start_counting_ticks() { prof_ticks = OS::get_singleton()->get_ticks_usec(); }
_FORCE_INLINE_ void stop_counting_ticks() { prof_time += OS::get_singleton()->get_ticks_usec() - prof_ticks; }
@@ -136,7 +138,6 @@ class AudioDriverManager {
MAX_DRIVERS = 10
};
- static const int DEFAULT_MIX_RATE = 44100;
static const int DEFAULT_OUTPUT_LATENCY = 15;
static AudioDriver *drivers[MAX_DRIVERS];
@@ -145,6 +146,8 @@ class AudioDriverManager {
static AudioDriverDummy dummy_driver;
public:
+ static const int DEFAULT_MIX_RATE = 44100;
+
static void add_driver(AudioDriver *p_driver);
static void initialize(int p_driver);
static int get_driver_count();