From 6e5334bd3e03273daa23776516ac1ec5ccf27fb7 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Sat, 24 Feb 2024 00:10:34 +0800 Subject: [PATCH] =?UTF-8?q?fixed=20a=20bug=20=20in=20AudioPlayer.cpp?= =?UTF-8?q?=EF=BC=8C=20thank=20oz01.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/AudioPlayer.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/AudioPlayer.cpp b/src/AudioPlayer.cpp index 76bb920..a101202 100644 --- a/src/AudioPlayer.cpp +++ b/src/AudioPlayer.cpp @@ -72,6 +72,8 @@ namespace hgl AudioPlayer::~AudioPlayer() { + SAFE_CLEAR(decode); + if(!audio_data)return; Clear(); @@ -87,11 +89,19 @@ namespace hgl if(!plugin_name)return(false); - AudioPlugInInterface decode; + decode=new AudioPlugInInterface; - if(GetAudioInterface(plugin_name,&decode,nullptr)) + if (!GetAudioInterface(plugin_name, decode, nullptr)) { - audio_ptr=decode.Open(audio_data,audio_data_size,&format,&rate,&total_time); + delete decode; + decode=nullptr; + + LOG_ERROR(OS_TEXT("无法加载音频解码插件:")+OSString(plugin_name)); + return(false); + } + + { + audio_ptr=decode->Open(audio_data,audio_data_size,&format,&rate,&total_time); audio_buffer_size=(AudioTime(format,rate)+9)/10; // 1/10 秒 @@ -107,7 +117,6 @@ namespace hgl return(true); } - else return(false); } /** @@ -242,6 +251,8 @@ namespace hgl bool AudioPlayer::ReadData(ALuint n) { + if(!decode)return(false); + uint size; size=decode->Read(audio_ptr,audio_buffer,audio_buffer_size); @@ -261,6 +272,7 @@ namespace hgl bool AudioPlayer::Playback() { if(!audio_data)return(false); + if(!decode)return(false); alSourceStop(source); ClearBuffer();