1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 19:13:07 +01:00

Remove null audio source and fix crash on exit

This commit is contained in:
Ted John
2022-05-18 01:08:51 +01:00
parent 1d0f9b584b
commit bb102cc1ec
7 changed files with 5 additions and 58 deletions

View File

@@ -232,8 +232,7 @@ namespace OpenRCT2::Audio
[[nodiscard]] AudioFormat GetFormat() const override
{
AudioFormat result = {};
// The second check is there because NullAudioSource does not implement GetFormat. Avoid calling it.
if (_source != nullptr && _source->GetLength() > 0)
if (_source != nullptr)
{
result = _source->GetFormat();
}

View File

@@ -50,7 +50,6 @@ namespace OpenRCT2::Audio
struct ISDLAudioSource : public IAudioSource
{
[[nodiscard]] virtual bool IsReleased() const abstract;
[[nodiscard]] virtual AudioFormat GetFormat() const abstract;
};

View File

@@ -17,15 +17,9 @@
using namespace OpenRCT2::Audio;
AudioMixer::AudioMixer()
{
_nullSource = AudioSource::CreateNull();
}
AudioMixer::~AudioMixer()
{
Close();
delete _nullSource;
}
void AudioMixer::Init(const char* device)
@@ -153,7 +147,9 @@ void AudioMixer::GetNextAudioChunk(uint8_t* dst, size_t length)
while (it != _channels.end())
{
auto channel = *it;
if ((channel->IsDone() && channel->DeleteOnDone()) || channel->IsStopping())
auto channelSource = channel->GetSource();
auto channelSourceReleased = channelSource == nullptr || channelSource->IsReleased();
if (channelSourceReleased || (channel->IsDone() && channel->DeleteOnDone()) || channel->IsStopping())
{
delete channel;
it = _channels.erase(it);

View File

@@ -29,7 +29,6 @@ namespace OpenRCT2::Audio
{
private:
std::vector<std::unique_ptr<ISDLAudioSource>> _sources;
IAudioSource* _nullSource = nullptr;
SDL_AudioDeviceID _deviceId = 0;
AudioFormat _format = {};
@@ -47,7 +46,6 @@ namespace OpenRCT2::Audio
std::mutex _mutex;
public:
AudioMixer();
~AudioMixer() override;
void Init(const char* device) override;
void Close() override;

View File

@@ -22,12 +22,8 @@ namespace OpenRCT2::Audio
virtual ~IAudioSource() = default;
virtual void Release() abstract;
virtual bool IsReleased() const abstract;
virtual uint64_t GetLength() const abstract;
virtual size_t Read(void* dst, uint64_t offset, size_t len) abstract;
};
namespace AudioSource
{
IAudioSource* CreateNull();
}
} // namespace OpenRCT2::Audio

View File

@@ -1,40 +0,0 @@
/*****************************************************************************
* Copyright (c) 2014-2020 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include "AudioSource.h"
#include "audio.h"
namespace OpenRCT2::Audio
{
/**
* An audio source representing silence.
*/
class NullAudioSource : public IAudioSource
{
public:
void Release() override
{
}
uint64_t GetLength() const override
{
return 0;
}
size_t Read([[maybe_unused]] void* dst, [[maybe_unused]] uint64_t offset, [[maybe_unused]] size_t len) override
{
return 0;
}
};
IAudioSource* AudioSource::CreateNull()
{
return new NullAudioSource();
}
} // namespace OpenRCT2::Audio

View File

@@ -625,7 +625,6 @@
<ClCompile Include="audio\Audio.cpp" />
<ClCompile Include="audio\AudioMixer.cpp" />
<ClCompile Include="audio\DummyAudioContext.cpp" />
<ClCompile Include="audio\NullAudioSource.cpp" />
<ClCompile Include="Cheats.cpp" />
<ClCompile Include="CmdlineSprite.cpp" />
<ClCompile Include="cmdline\BenchGfxCommmands.cpp" />