Add destructor for SoundTrack/MusicTrack (and explicitly define move constructor to prevent double-free)

This commit is contained in:
leo60228
2020-01-30 09:49:34 -05:00
committed by Ethan Lee
parent c561cd9740
commit 2f760af439
3 changed files with 99 additions and 62 deletions

View File

@@ -8,6 +8,9 @@ class MusicTrack
public:
MusicTrack(const char* fileName);
MusicTrack(SDL_RWops *rw);
MusicTrack(MusicTrack&& moved);
MusicTrack& operator=(const MusicTrack& other) = default;
~MusicTrack();
Mix_Music *m_music;
bool m_isValid;
};
@@ -16,7 +19,12 @@ class SoundTrack
{
public:
SoundTrack(const char* fileName);
SoundTrack(SoundTrack&& moved);
SoundTrack& operator=(const SoundTrack& other) = default;
SoundTrack() = default;
~SoundTrack();
Mix_Chunk *sound;
bool isValid = false;
};
class SoundSystem
@@ -26,4 +34,14 @@ public:
void playMusic(MusicTrack* music);
};
// polyfill of std::move
template<typename T> struct remove_reference {typedef T type;};
template<typename T> struct remove_reference<T&> {typedef T type;};
template<typename T> struct remove_reference<T&&> {typedef T type;};
template<typename T>
typename remove_reference<T>::type&& move(T&& t) {
return static_cast<typename remove_reference<T>::type&&>(t);
}
#endif /* SOUNDSYSTEM_H */