From 7973d70b042a79da2d1cd10c544608e259057478 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Thu, 25 Jun 2020 01:24:30 -0700 Subject: [PATCH] mVL: Add parameter for closing the video log backing --- include/mgba/feature/video-logger.h | 2 +- src/feature/video-logger.c | 6 +++++- src/gb/core.c | 4 ++-- src/gba/core.c | 4 ++-- src/platform/qt/CoreController.cpp | 5 ++--- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/include/mgba/feature/video-logger.h b/include/mgba/feature/video-logger.h index b40caff6d..2530d3fa2 100644 --- a/include/mgba/feature/video-logger.h +++ b/include/mgba/feature/video-logger.h @@ -117,7 +117,7 @@ void mVideoLogContextSetOutput(struct mVideoLogContext*, struct VFile*); void mVideoLogContextWriteHeader(struct mVideoLogContext*, struct mCore* core); bool mVideoLogContextLoad(struct mVideoLogContext*, struct VFile*); -void mVideoLogContextDestroy(struct mCore* core, struct mVideoLogContext*); +void mVideoLogContextDestroy(struct mCore* core, struct mVideoLogContext*, bool closeVF); void mVideoLogContextRewind(struct mVideoLogContext*, struct mCore*); void* mVideoLogContextInitialState(struct mVideoLogContext*, size_t* size); diff --git a/src/feature/video-logger.c b/src/feature/video-logger.c index e28e20ac1..e25b1a44c 100644 --- a/src/feature/video-logger.c +++ b/src/feature/video-logger.c @@ -723,7 +723,7 @@ static void _flushBuffer(struct mVideoLogContext* context) { } } -void mVideoLogContextDestroy(struct mCore* core, struct mVideoLogContext* context) { +void mVideoLogContextDestroy(struct mCore* core, struct mVideoLogContext* context, bool closeVF) { if (context->write) { _flushBuffer(context); @@ -751,6 +751,10 @@ void mVideoLogContextDestroy(struct mCore* core, struct mVideoLogContext* contex #endif } + if (closeVF && context->backing) { + context->backing->close(context->backing); + } + free(context); } diff --git a/src/gb/core.c b/src/gb/core.c index a3dd7dd79..b42bcbf1e 100644 --- a/src/gb/core.c +++ b/src/gb/core.c @@ -1066,7 +1066,7 @@ static bool _GBVLPInit(struct mCore* core) { static void _GBVLPDeinit(struct mCore* core) { struct GBCore* gbcore = (struct GBCore*) core; if (gbcore->logContext) { - mVideoLogContextDestroy(core, gbcore->logContext); + mVideoLogContextDestroy(core, gbcore->logContext, true); } _GBCoreDeinit(core); } @@ -1095,7 +1095,7 @@ static bool _GBVLPLoadROM(struct mCore* core, struct VFile* vf) { struct GBCore* gbcore = (struct GBCore*) core; gbcore->logContext = mVideoLogContextCreate(NULL); if (!mVideoLogContextLoad(gbcore->logContext, vf)) { - mVideoLogContextDestroy(core, gbcore->logContext); + mVideoLogContextDestroy(core, gbcore->logContext, false); gbcore->logContext = NULL; return false; } diff --git a/src/gba/core.c b/src/gba/core.c index a1cd7f187..c8f9c7348 100644 --- a/src/gba/core.c +++ b/src/gba/core.c @@ -1224,7 +1224,7 @@ static bool _GBAVLPInit(struct mCore* core) { static void _GBAVLPDeinit(struct mCore* core) { struct GBACore* gbacore = (struct GBACore*) core; if (gbacore->logContext) { - mVideoLogContextDestroy(core, gbacore->logContext); + mVideoLogContextDestroy(core, gbacore->logContext, true); } _GBACoreDeinit(core); } @@ -1253,7 +1253,7 @@ static bool _GBAVLPLoadROM(struct mCore* core, struct VFile* vf) { struct GBACore* gbacore = (struct GBACore*) core; gbacore->logContext = mVideoLogContextCreate(NULL); if (!mVideoLogContextLoad(gbacore->logContext, vf)) { - mVideoLogContextDestroy(core, gbacore->logContext); + mVideoLogContextDestroy(core, gbacore->logContext, false); gbacore->logContext = NULL; return false; } diff --git a/src/platform/qt/CoreController.cpp b/src/platform/qt/CoreController.cpp index 5ecca6870..99fc0299d 100644 --- a/src/platform/qt/CoreController.cpp +++ b/src/platform/qt/CoreController.cpp @@ -871,9 +871,8 @@ void CoreController::endVideoLog(bool closeVf) { } Interrupter interrupter(this); - mVideoLogContextDestroy(m_threadContext.core, m_vl); - if (m_vlVf && closeVf) { - m_vlVf->close(m_vlVf); + mVideoLogContextDestroy(m_threadContext.core, m_vl, closeVf); + if (closeVf) { m_vlVf = nullptr; } m_vl = nullptr;