mirror of
https://github.com/clangen/musikcube.git
synced 2025-03-14 04:18:36 +00:00
Fixed bug in Player::Destroy() that could try to detach an already
detached thread, leading to a crash.
This commit is contained in:
parent
167d7aeb1c
commit
5f7f2ac0e0
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user