Release msu data and audio streams on exit, use unzClose when closing file

This commit is contained in:
OV2 2017-10-14 00:08:39 +02:00
parent e014129b12
commit a66b88b276
4 changed files with 36 additions and 25 deletions

View File

@ -624,6 +624,8 @@ void S9xDeinitAPU (void)
delete[] msu::resample_buffer;
msu::resample_buffer = NULL;
}
S9xMSU1DeInit();
}
static inline int S9xAPUGetClock (int32 cpucycles)

View File

@ -274,7 +274,7 @@ STREAM S9xMSU1OpenFile(const char *msu_ext, bool skip_unpacked)
file = new unzStream(unzFile);
}
else
unzCloseCurrentFile(unzFile);
unzClose(unzFile);
}
}
#endif
@ -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);
@ -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");
@ -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();
}
@ -378,6 +380,12 @@ void S9xMSU1Init(void)
DataOpen();
}
void S9xMSU1DeInit(void)
{
DataClose();
AudioClose();
}
bool S9xMSU1ROMExists(void)
{
STREAM s = S9xMSU1OpenFile(".msu");
@ -399,7 +407,7 @@ bool S9xMSU1ROMExists(void)
if (unzFile)
{
unzCloseCurrentFile(unzFile);
unzClose(unzFile);
return true;
}
#endif

1
msu1.h
View File

@ -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);

View File

@ -451,7 +451,7 @@ int unzStream::revert (size_t from, size_t offset)
void unzStream::closeStream()
{
unzCloseCurrentFile(file);
unzClose(file);
delete this;
}