From a66b88b276bd7f31a76a258d0d31b28cafef2d45 Mon Sep 17 00:00:00 2001 From: OV2 Date: Sat, 14 Oct 2017 00:08:39 +0200 Subject: [PATCH] Release msu data and audio streams on exit, use unzClose when closing file --- apu/apu.cpp | 2 ++ msu1.cpp | 56 ++++++++++++++++++++++++++++++----------------------- msu1.h | 1 + stream.cpp | 2 +- 4 files changed, 36 insertions(+), 25 deletions(-) diff --git a/apu/apu.cpp b/apu/apu.cpp index db2abdc8..daeaebf0 100644 --- a/apu/apu.cpp +++ b/apu/apu.cpp @@ -624,6 +624,8 @@ void S9xDeinitAPU (void) delete[] msu::resample_buffer; msu::resample_buffer = NULL; } + + S9xMSU1DeInit(); } static inline int S9xAPUGetClock (int32 cpucycles) diff --git a/msu1.cpp b/msu1.cpp index 25b8b597..66da4ad9 100644 --- a/msu1.cpp +++ b/msu1.cpp @@ -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 diff --git a/msu1.h b/msu1.h index 8838bc29..21df0630 100644 --- a/msu1.h +++ b/msu1.h @@ -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); diff --git a/stream.cpp b/stream.cpp index 204a7719..872e9bd5 100644 --- a/stream.cpp +++ b/stream.cpp @@ -451,7 +451,7 @@ int unzStream::revert (size_t from, size_t offset) void unzStream::closeStream() { - unzCloseCurrentFile(file); + unzClose(file); delete this; }