mirror of https://github.com/OpenRCT2/OpenRCT2.git
Merge pull request #17465 from IntelOrca/fix/17462-audio-crash
Fix #17462: Crash when zooming or moving around the park
This commit is contained in:
commit
c823bf5f7e
|
@ -9,6 +9,8 @@
|
|||
|
||||
#include "SDLAudioSource.h"
|
||||
|
||||
#include <openrct2/Context.h>
|
||||
#include <openrct2/audio/AudioContext.h>
|
||||
#include <stdexcept>
|
||||
|
||||
using namespace OpenRCT2::Audio;
|
||||
|
@ -30,11 +32,34 @@ void SDLAudioSource::Release()
|
|||
{
|
||||
if (!_released)
|
||||
{
|
||||
// Lock the mixer to make sure we aren't mixing
|
||||
// the source as we dispose it
|
||||
auto mixer = GetMixer();
|
||||
if (mixer != nullptr)
|
||||
mixer->Lock();
|
||||
|
||||
Unload();
|
||||
|
||||
if (mixer != nullptr)
|
||||
mixer->Unlock();
|
||||
|
||||
_released = true;
|
||||
}
|
||||
}
|
||||
|
||||
IAudioMixer* SDLAudioSource::GetMixer()
|
||||
{
|
||||
auto ctx = GetContext();
|
||||
if (ctx == nullptr)
|
||||
return nullptr;
|
||||
|
||||
auto audioContext = ctx->GetAudioContext();
|
||||
if (audioContext == nullptr)
|
||||
return nullptr;
|
||||
|
||||
return audioContext->GetMixer();
|
||||
}
|
||||
|
||||
int32_t SDLAudioSource::GetBytesPerSecond() const
|
||||
{
|
||||
auto format = GetFormat();
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
|
||||
namespace OpenRCT2::Audio
|
||||
{
|
||||
struct IAudioMixer;
|
||||
|
||||
#ifdef __WARN_SUGGEST_FINAL_METHODS__
|
||||
# pragma GCC diagnostic push
|
||||
# pragma GCC diagnostic ignored "-Wsuggest-final-methods"
|
||||
|
@ -38,6 +40,9 @@ namespace OpenRCT2::Audio
|
|||
|
||||
protected:
|
||||
virtual void Unload() = 0;
|
||||
|
||||
private:
|
||||
IAudioMixer* GetMixer();
|
||||
};
|
||||
#ifdef __WARN_SUGGEST_FINAL_METHODS__
|
||||
# pragma GCC diagnostic pop
|
||||
|
|
|
@ -202,7 +202,7 @@ namespace OpenRCT2::RideAudio
|
|||
auto source = audioObj->GetSample(0);
|
||||
if (source != nullptr)
|
||||
{
|
||||
auto channel = CreateAudioChannel(source, MixerGroup::Sound, false);
|
||||
auto channel = CreateAudioChannel(source, MixerGroup::Sound, false, 0);
|
||||
if (channel != nullptr)
|
||||
{
|
||||
_musicChannels.emplace_back(instance, channel, nullptr);
|
||||
|
@ -226,7 +226,7 @@ namespace OpenRCT2::RideAudio
|
|||
if (source != nullptr)
|
||||
{
|
||||
auto shouldLoop = musicObj->GetTrackCount() == 1;
|
||||
auto channel = CreateAudioChannel(source, MixerGroup::RideMusic, shouldLoop);
|
||||
auto channel = CreateAudioChannel(source, MixerGroup::RideMusic, shouldLoop, 0);
|
||||
if (channel != nullptr)
|
||||
{
|
||||
_musicChannels.emplace_back(instance, channel, source);
|
||||
|
|
Loading…
Reference in New Issue