diff --git a/SDL2pp/AudioDevice.cc b/SDL2pp/AudioDevice.cc index b30b4e6..43da4cd 100644 --- a/SDL2pp/AudioDevice.cc +++ b/SDL2pp/AudioDevice.cc @@ -51,6 +51,9 @@ AudioDevice::AudioDevice(AudioDevice&& other) noexcept : device_id_(other.device } AudioDevice& AudioDevice::operator=(AudioDevice&& other) noexcept { + if (&other == this) + return *this; + if (device_id_) SDL_CloseAudioDevice(device_id_); diff --git a/SDL2pp/AudioLock.cc b/SDL2pp/AudioLock.cc index 3709da4..d426856 100644 --- a/SDL2pp/AudioLock.cc +++ b/SDL2pp/AudioLock.cc @@ -37,6 +37,12 @@ AudioDevice::LockHandle::LockHandle(AudioDevice::LockHandle&& other) noexcept : } AudioDevice::LockHandle& AudioDevice::LockHandle::operator=(AudioDevice::LockHandle&& other) noexcept { + if (&other == this) + return *this; + + if (device_ != nullptr) + SDL_UnlockAudioDevice(device_->device_id_); + device_ = other.device_; other.device_ = nullptr; diff --git a/SDL2pp/RWops.cc b/SDL2pp/RWops.cc index 4f8d951..486cebd 100644 --- a/SDL2pp/RWops.cc +++ b/SDL2pp/RWops.cc @@ -149,6 +149,10 @@ RWops::RWops(RWops&& other) noexcept : rwops_(other.rwops_) { } RWops& RWops::operator=(RWops&& other) noexcept { + if (&other == this) + return *this; + if (rwops_ != nullptr) + Close(); rwops_ = other.rwops_; rwops_->hidden.unknown.data2 = static_cast(this); other.rwops_ = nullptr; diff --git a/SDL2pp/Renderer.cc b/SDL2pp/Renderer.cc index bc62564..f72730f 100644 --- a/SDL2pp/Renderer.cc +++ b/SDL2pp/Renderer.cc @@ -47,6 +47,10 @@ Renderer::Renderer(Renderer&& other) noexcept : renderer_(other.renderer_) { } Renderer& Renderer::operator=(Renderer&& other) noexcept { + if (&other == this) + return *this; + if (renderer_ != nullptr) + SDL_DestroyRenderer(renderer_); renderer_ = other.renderer_; other.renderer_ = nullptr; return *this; diff --git a/SDL2pp/Texture.cc b/SDL2pp/Texture.cc index 85923be..947f6d5 100644 --- a/SDL2pp/Texture.cc +++ b/SDL2pp/Texture.cc @@ -65,6 +65,10 @@ Texture::Texture(Texture&& other) noexcept : texture_(other.texture_) { } Texture& Texture::operator=(Texture&& other) noexcept { + if (&other == this) + return *this; + if (texture_ != nullptr) + SDL_DestroyTexture(texture_); texture_ = other.texture_; other.texture_ = nullptr; return *this; diff --git a/SDL2pp/TextureLock.cc b/SDL2pp/TextureLock.cc index 8230499..325276b 100644 --- a/SDL2pp/TextureLock.cc +++ b/SDL2pp/TextureLock.cc @@ -38,6 +38,12 @@ Texture::LockHandle::LockHandle(Texture::LockHandle&& other) noexcept : texture_ } Texture::LockHandle& Texture::LockHandle::operator=(Texture::LockHandle&& other) noexcept { + if (&other == this) + return *this; + + if (texture_ != nullptr) + SDL_UnlockTexture(texture_->Get()); + texture_ = other.texture_; pixels_ = other.pixels_; pitch_ = other.pitch_; diff --git a/SDL2pp/Wav.cc b/SDL2pp/Wav.cc index 76b062b..cdd59d0 100644 --- a/SDL2pp/Wav.cc +++ b/SDL2pp/Wav.cc @@ -47,6 +47,12 @@ Wav::Wav(Wav&& other) : audio_buffer_(other.audio_buffer_), audio_length_(other. } Wav& Wav::operator=(Wav&& other) { + if (&other == this) + return *this; + + if (audio_buffer_ != nullptr) + SDL_FreeWAV(audio_buffer_); + spec_ = std::move(other.spec_); audio_buffer_ = other.audio_buffer_; audio_length_ = other.audio_length_; diff --git a/SDL2pp/Window.cc b/SDL2pp/Window.cc index ce9f064..e45a147 100644 --- a/SDL2pp/Window.cc +++ b/SDL2pp/Window.cc @@ -41,6 +41,10 @@ Window::Window(Window&& other) noexcept : window_(other.window_) { } Window& Window::operator=(Window&& other) noexcept { + if (&other == this) + return *this; + if (window_ != nullptr) + SDL_DestroyWindow(window_); window_ = other.window_; other.window_ = nullptr; return *this;