summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcelo Fernandez <marcelofg55@gmail.com>2019-03-01 09:33:15 -0300
committerMarcelo Fernandez <marcelofg55@gmail.com>2019-03-01 09:33:15 -0300
commitf04bff349bbfb41a9f774edac3910689b9f10918 (patch)
tree8c66fb78fb7305a56c882dfd84c6b39412f59b41
parente7dd05fed80d80b328977450bc3a48f500d5cd44 (diff)
Fix possible crash when AudioDriver::capture_start fails
-rw-r--r--servers/audio/audio_stream.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/servers/audio/audio_stream.cpp b/servers/audio/audio_stream.cpp
index 12ee98595d..a6c262d10f 100644
--- a/servers/audio/audio_stream.cpp
+++ b/servers/audio/audio_stream.cpp
@@ -186,6 +186,10 @@ float AudioStreamPlaybackMicrophone::get_stream_sampling_rate() {
void AudioStreamPlaybackMicrophone::start(float p_from_pos) {
+ if (active) {
+ return;
+ }
+
if (!GLOBAL_GET("audio/enable_audio_input")) {
WARN_PRINTS("Need to enable Project settings > Audio > Enable Audio Input option to use capturing.");
return;
@@ -193,15 +197,17 @@ void AudioStreamPlaybackMicrophone::start(float p_from_pos) {
input_ofs = 0;
- AudioDriver::get_singleton()->capture_start();
-
- active = true;
- _begin_resample();
+ if (AudioDriver::get_singleton()->capture_start() == OK) {
+ active = true;
+ _begin_resample();
+ }
}
void AudioStreamPlaybackMicrophone::stop() {
- AudioDriver::get_singleton()->capture_stop();
- active = false;
+ if (active) {
+ AudioDriver::get_singleton()->capture_stop();
+ active = false;
+ }
}
bool AudioStreamPlaybackMicrophone::is_playing() const {