From 1c9af767e5ee62e28835025e838b02ab277dea00 Mon Sep 17 00:00:00 2001
From: Thomas Goyne <plorkyeran@aegisub.org>
Date: Sat, 1 Sep 2012 21:43:06 -0700
Subject: [PATCH] Move audio decode error handling to GetAudio

Errors when not getting with volume need to be handled too.

Updates #1509.
---
 aegisub/src/audio_provider.cpp | 35 +++++++++++++++++-----------------
 1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/aegisub/src/audio_provider.cpp b/aegisub/src/audio_provider.cpp
index 72517bc8a..1482a56d6 100644
--- a/aegisub/src/audio_provider.cpp
+++ b/aegisub/src/audio_provider.cpp
@@ -61,21 +61,7 @@
 #include <libaegisub/log.h>
 
 void AudioProvider::GetAudioWithVolume(void *buf, int64_t start, int64_t count, double volume) const {
-	try {
-		GetAudio(buf,start,count);
-	}
-	catch (AudioDecodeError const& e) {
-		LOG_E("audio_provider") << e.GetChainedMessage();
-		memset(buf, 0, count*bytes_per_sample);
-		return;
-	}
-	catch (...) {
-		// FIXME: Poor error handling though better than none, to patch issue #800.
-		// Just return blank audio if real provider fails.
-		LOG_E("audio_provider") << "Unknown audio decoding error";
-		memset(buf, 0, count*bytes_per_sample);
-		return;
-	}
+	GetAudio(buf,start,count);
 
 	if (volume == 1.0) return;
 
@@ -128,8 +114,23 @@ void AudioProvider::GetAudio(void *buf, int64_t start, int64_t count) const {
 			memset(zero_buf, 0, zero_count * bytes_per_sample * channels);
 	}
 
-	if (count > 0)
-		FillBuffer(buf, start, count);
+	if (count > 0) {
+		try {
+			FillBuffer(buf, start, count);
+		}
+		catch (AudioDecodeError const& e) {
+			LOG_E("audio_provider") << e.GetChainedMessage();
+			memset(buf, 0, count*bytes_per_sample);
+			return;
+		}
+		catch (...) {
+			// FIXME: Poor error handling though better than none, to patch issue #800.
+			// Just return blank audio if real provider fails.
+			LOG_E("audio_provider") << "Unknown audio decoding error";
+			memset(buf, 0, count*bytes_per_sample);
+			return;
+		}
+	}
 }
 
 AudioProvider *AudioProviderFactory::GetProvider(wxString const& filename, int cache) {
-- 
GitLab