From 8290423d16952e8e83912c0dcd5b7ef39e4f8723 Mon Sep 17 00:00:00 2001 From: liushuyu Date: Sat, 12 Dec 2020 02:09:29 -0700 Subject: [PATCH] bootmanager: fix memory leaks when loading save states --- src/citra_qt/bootmanager.cpp | 8 ++++---- src/citra_qt/bootmanager.h | 7 ++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/citra_qt/bootmanager.cpp b/src/citra_qt/bootmanager.cpp index 18f7e8ea65..b3c6fc5950 100644 --- a/src/citra_qt/bootmanager.cpp +++ b/src/citra_qt/bootmanager.cpp @@ -104,7 +104,7 @@ void EmuThread::run() { } OpenGLWindow::OpenGLWindow(QWindow* parent, QWidget* event_handler, QOpenGLContext* shared_context) - : QWindow(parent), context(new QOpenGLContext(shared_context->parent())), + : QWindow(parent), context(std::make_unique(shared_context->parent())), event_handler(event_handler) { // disable vsync for any shared contexts @@ -447,8 +447,8 @@ std::unique_ptr GRenderWindow::CreateSharedContext() } GLContext::GLContext(QOpenGLContext* shared_context) - : context(new QOpenGLContext(shared_context->parent())), - surface(new QOffscreenSurface(nullptr)) { + : context(std::make_unique(shared_context->parent())), + surface(std::make_unique(nullptr)) { // disable vsync for any shared contexts auto format = shared_context->format(); @@ -463,7 +463,7 @@ GLContext::GLContext(QOpenGLContext* shared_context) } void GLContext::MakeCurrent() { - context->makeCurrent(surface); + context->makeCurrent(surface.get()); } void GLContext::DoneCurrent() { diff --git a/src/citra_qt/bootmanager.h b/src/citra_qt/bootmanager.h index 3dec9751ba..40946abb67 100644 --- a/src/citra_qt/bootmanager.h +++ b/src/citra_qt/bootmanager.h @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -36,8 +37,8 @@ public: void DoneCurrent() override; private: - QOpenGLContext* context; - QOffscreenSurface* surface; + std::unique_ptr context; + std::unique_ptr surface; }; class EmuThread final : public QThread { @@ -138,7 +139,7 @@ protected: void exposeEvent(QExposeEvent* event) override; private: - QOpenGLContext* context; + std::unique_ptr context; QWidget* event_handler; };