Skip to content

Commit

Permalink
Release msu data and audio streams on exit, use unzClose when closing…
Browse files Browse the repository at this point in the history
… file
  • Loading branch information
OV2 committed Oct 13, 2017
1 parent e014129 commit a66b88b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 25 deletions.
2 changes: 2 additions & 0 deletions apu/apu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,8 @@ void S9xDeinitAPU (void)
delete[] msu::resample_buffer;
msu::resample_buffer = NULL;
}

S9xMSU1DeInit();
}

static inline int S9xAPUGetClock (int32 cpucycles)
Expand Down
56 changes: 32 additions & 24 deletions msu1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ STREAM S9xMSU1OpenFile(const char *msu_ext, bool skip_unpacked)
file = new unzStream(unzFile);
}
else
unzCloseCurrentFile(unzFile);
unzClose(unzFile);
}
}
#endif
Expand All @@ -285,15 +285,20 @@ STREAM S9xMSU1OpenFile(const char *msu_ext, bool skip_unpacked)
return file;
}

bool AudioOpen()
static void AudioClose()
{
if (audioStream)
{
CLOSE_STREAM(audioStream);
audioStream = NULL;
}
}

static bool AudioOpen()
{
MSU1.MSU1_STATUS |= AudioError;

if (audioStream)
{
CLOSE_STREAM(audioStream);
audioStream = NULL;
}
AudioClose();

char ext[_MAX_EXT];
snprintf(ext, _MAX_EXT, "-%d.pcm", MSU1.MSU1_CURRENT_TRACK);
Expand Down Expand Up @@ -322,13 +327,18 @@ bool AudioOpen()
return false;
}

bool DataOpen()
static void DataClose()
{
if (dataStream)
{
CLOSE_STREAM(dataStream);
dataStream = NULL;
}
if (dataStream)
{
CLOSE_STREAM(dataStream);
dataStream = NULL;
}
}

static bool DataOpen()
{
DataClose();

dataStream = S9xMSU1OpenFile(".msu");

Expand Down Expand Up @@ -358,17 +368,9 @@ void S9xResetMSU(void)

partial_samples = 0;

if (dataStream)
{
CLOSE_STREAM(dataStream);
dataStream = NULL;
}
DataClose();

if (audioStream)
{
CLOSE_STREAM(audioStream);
audioStream = NULL;
}
AudioClose();

Settings.MSU1 = S9xMSU1ROMExists();
}
Expand All @@ -378,6 +380,12 @@ void S9xMSU1Init(void)
DataOpen();
}

void S9xMSU1DeInit(void)
{
DataClose();
AudioClose();
}

bool S9xMSU1ROMExists(void)
{
STREAM s = S9xMSU1OpenFile(".msu");
Expand All @@ -399,7 +407,7 @@ bool S9xMSU1ROMExists(void)

if (unzFile)
{
unzCloseCurrentFile(unzFile);
unzClose(unzFile);
return true;
}
#endif
Expand Down
1 change: 1 addition & 0 deletions msu1.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ extern struct SMSU1 MSU1;

void S9xResetMSU(void);
void S9xMSU1Init(void);
void S9xMSU1DeInit(void);
bool S9xMSU1ROMExists(void);
STREAM S9xMSU1OpenFile(const char *msu_ext, bool skip_unpacked = FALSE);
void S9xMSU1Init(void);
Expand Down
2 changes: 1 addition & 1 deletion stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ int unzStream::revert (size_t from, size_t offset)

void unzStream::closeStream()
{
unzCloseCurrentFile(file);
unzClose(file);
delete this;
}

Expand Down

0 comments on commit a66b88b

Please sign in to comment.