Fixed bug in Player::Destroy() that could try to detach an already

detached thread, leading to a crash.
This commit is contained in:
casey langen 2016-12-23 16:09:48 -08:00
parent 167d7aeb1c
commit 5f7f2ac0e0
2 changed files with 6 additions and 5 deletions

View File

@ -120,14 +120,12 @@ Player::Player(const std::string &url, std::shared_ptr<IOutput> output, PlayerEv
this->spectrum = new float[FFT_N / 2];
/* we allow callers to specify an output device; but if they don't,
we will create and manage our own. */
if (!this->output) {
throw std::runtime_error("output cannot be null!");
}
/* each player instance is driven by a background thread. start it. */
this->thread.reset(new std::thread(std::bind(&musik::core::audio::playerThreadLoop, this)));
this->thread = new std::thread(std::bind(&musik::core::audio::playerThreadLoop, this));
}
Player::~Player() {
@ -155,6 +153,8 @@ void Player::Destroy() {
this->state = Player::Quit;
this->writeToOutputCondition.notify_all();
this->thread->detach();
delete this->thread;
this->thread = nullptr;
}
}
@ -345,6 +345,8 @@ void musik::core::audio::playerThreadLoop(Player* player) {
player->listener->OnPlayerDestroying(player);
}
player->Destroy();
delete player;
}

View File

@ -108,7 +108,6 @@ namespace musik { namespace core { namespace audio {
virtual ~Player();
typedef std::shared_ptr<std::thread> ThreadPtr;
typedef std::list<BufferPtr> BufferList;
typedef std::set<BufferPtr> BufferSet;
@ -120,7 +119,7 @@ namespace musik { namespace core { namespace audio {
std::shared_ptr<musik::core::sdk::IOutput> output;
StreamPtr stream;
ThreadPtr thread;
std::thread* thread;
BufferList lockedBuffers;
PlayerEventListener* listener;