diff --git a/SDL2pp/AudioDevice.hh b/SDL2pp/AudioDevice.hh index 7d87f3d..2c85c02 100644 --- a/SDL2pp/AudioDevice.hh +++ b/SDL2pp/AudioDevice.hh @@ -50,8 +50,8 @@ public: LockHandle(LockHandle&& other) noexcept; LockHandle& operator=(LockHandle&& other) noexcept; - LockHandle(const LockHandle& other) = delete; - LockHandle& operator=(const LockHandle& other) = delete; + LockHandle(const LockHandle& other); + LockHandle& operator=(const LockHandle& other); }; typedef std::function AudioCallback; diff --git a/SDL2pp/AudioLock.cc b/SDL2pp/AudioLock.cc index 55a1383..159c518 100644 --- a/SDL2pp/AudioLock.cc +++ b/SDL2pp/AudioLock.cc @@ -53,4 +53,21 @@ AudioDevice::LockHandle& AudioDevice::LockHandle::operator=(AudioDevice::LockHan return *this; } +AudioDevice::LockHandle::LockHandle(const AudioDevice::LockHandle& other) : device_(other.device_) { + SDL_LockAudioDevice(device_->device_id_); +} + +AudioDevice::LockHandle& AudioDevice::LockHandle::operator=(const AudioDevice::LockHandle& other) { + if (&other == this) + return *this; + + if (device_ != nullptr) + SDL_UnlockAudioDevice(device_->device_id_); + + device_ = other.device_; + SDL_LockAudioDevice(device_->device_id_); + + return *this; +} + }