1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-29 07:58:30 +02:00
VVVVVV/desktop_version/src/Music.h
Misa 77748f29f9 Separate musicReadBlob into mmmmmm_blob and pppppp_blob
musicReadBlob was used for both MMMMMM and PPPPPP soundtracks. This
causes a memory leak if you have mmmmmm.vvv installed, because the
pointers holding each allocated block of MMMMMM would be lost when
PPPPPP got loaded. Valgrind complains about this memory leak.

This is in contrast to 2.2 and previous behavior, where musicReadBlob
was only a temporary object instead of being held in musicclass.
However, this wasn't really a memory leak (moreso something that just
didn't get cleaned up when closing the game), but it did get turned into
a leak when per-level assets mounting and unmounting got introduced in
2.3 (loading a level with custom assets after starting the game with an
mmmmmm.vvv, or exiting out of a level that had an mmmmmm.vvv, would
cause the game to leak memory). Leo recognized this, and moved
musicReadBlob onto musicclass in a separate 2.3 PR, but either he didn't
think about what was happening here too closely, or he didn't use
Valgrind, because he forgot about the memory leak caused by re-using the
same binaryBlob for PPPPPP and MMMMMM.

So instead, just use two different binaryBlob objects for MMMMMM and
PPPPPP. That way, no memory leaks happen.
2021-02-15 23:07:35 -05:00

68 lines
1.2 KiB
C++

#ifndef MUSIC_H
#define MUSIC_H
#include <vector>
#include "BinaryBlob.h"
#include "SoundSystem.h"
#define musicroom(rx, ry) ((rx) + ((ry) * 20))
class musicclass
{
public:
musicclass();
void init();
void destroy();
void play(int t, const double position_sec = 0.0, const int fadein_ms = 3000);
void resume(const int fadein_ms = 0);
void haltdasmusik();
void silencedasmusik();
void fadeMusicVolumeIn(int ms);
void fadeout(const bool quick_fade_ = true);
void fadein();
void processmusicfadein();
void processmusic();
void niceplay(int t);
void changemusicarea(int x, int y);
int currentsong;
int resumesong;
void playef(int t);
std::vector<SoundTrack> soundTracks;
std::vector<MusicTrack> musicTracks;
SoundSystem soundSystem;
bool safeToProcessMusic;
int nicechange; // -1 if no song queued
bool nicefade;
bool m_doFadeInVol;
int FadeVolAmountPerFrame;
int musicVolume;
bool quick_fade;
// MMMMMM mod settings
bool mmmmmm;
bool usingmmmmmm;
binaryBlob pppppp_blob;
binaryBlob mmmmmm_blob;
int num_pppppp_tracks;
int num_mmmmmm_tracks;
Uint64 songStart;
Uint64 songEnd;
};
#ifndef MUSIC_DEFINITION
extern musicclass music;
#endif
#endif /* MUSIC_H */