diff --git a/Source/Core/DolphinWX/Frame.cpp b/Source/Core/DolphinWX/Frame.cpp index f84d44ebf2..946cd52da3 100644 --- a/Source/Core/DolphinWX/Frame.cpp +++ b/Source/Core/DolphinWX/Frame.cpp @@ -508,15 +508,13 @@ CFrame::CFrame(wxFrame* parent, // check if game is running m_bHotkeysInit = InitControllers(); - m_poll_hotkey_timer = new wxTimer(this); + m_poll_hotkey_timer.SetOwner(this); Bind(wxEVT_TIMER, &CFrame::PollHotkeys, this); - m_poll_hotkey_timer->Start(1000 / 60, wxTIMER_CONTINUOUS); + m_poll_hotkey_timer.Start(1000 / 60, wxTIMER_CONTINUOUS); } // Destructor CFrame::~CFrame() { - m_poll_hotkey_timer->Stop(); - if (m_bHotkeysInit) { Wiimote::Shutdown(); diff --git a/Source/Core/DolphinWX/Frame.h b/Source/Core/DolphinWX/Frame.h index bcb51447ad..f670c27378 100644 --- a/Source/Core/DolphinWX/Frame.h +++ b/Source/Core/DolphinWX/Frame.h @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -47,8 +48,6 @@ class wxAuiNotebook; class wxAuiNotebookEvent; class wxListEvent; class wxMenuItem; -class wxTimer; -class wxTimerEvent; class wxWindow; class CRenderFrame : public wxFrame @@ -198,7 +197,7 @@ private: EToolbar_Max }; - wxTimer* m_poll_hotkey_timer; + wxTimer m_poll_hotkey_timer; wxBitmap m_Bitmaps[EToolbar_Max]; wxBitmap m_BitmapsMenu[EToolbar_Max]; diff --git a/Source/Core/DolphinWX/LogWindow.cpp b/Source/Core/DolphinWX/LogWindow.cpp index 4771c1d594..8212b110d9 100644 --- a/Source/Core/DolphinWX/LogWindow.cpp +++ b/Source/Core/DolphinWX/LogWindow.cpp @@ -45,7 +45,7 @@ CLogWindow::CLogWindow(CFrame *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name) : wxPanel(parent, id, pos, size, style, name) , x(0), y(0), winpos(0) - , Parent(parent), m_ignoreLogTimer(false), m_LogAccess(true) + , Parent(parent), m_LogAccess(true) , m_Log(nullptr), m_cmdline(nullptr), m_FontChoice(nullptr) { Bind(wxEVT_CLOSE_WINDOW, &CLogWindow::OnClose, this); @@ -55,8 +55,8 @@ CLogWindow::CLogWindow(CFrame *parent, wxWindowID id, const wxPoint& pos, CreateGUIControls(); - m_LogTimer = new wxTimer(this); - m_LogTimer->Start(UPDATETIME); + m_LogTimer.SetOwner(this); + m_LogTimer.Start(UPDATETIME); } void CLogWindow::CreateGUIControls() @@ -177,8 +177,6 @@ CLogWindow::~CLogWindow() { m_LogManager->RemoveListener((LogTypes::LOG_TYPE)i, this); } - m_LogTimer->Stop(); - delete m_LogTimer; } void CLogWindow::OnClose(wxCloseEvent& event) @@ -287,7 +285,7 @@ void CLogWindow::OnWrapLineCheck(wxCommandEvent& event) void CLogWindow::OnLogTimer(wxTimerEvent& WXUNUSED(event)) { - if (!m_LogAccess || m_ignoreLogTimer) + if (!m_LogAccess) return; UpdateLog(); @@ -302,13 +300,10 @@ void CLogWindow::OnLogTimer(wxTimerEvent& WXUNUSED(event)) void CLogWindow::UpdateLog() { - if (!m_LogAccess || !m_Log) + if (!m_LogAccess || !m_Log || msgQueue.empty()) return; - // m_LogTimer->Stop(); - // instead of stopping the timer, let's simply ignore its calls during UpdateLog, - // because repeatedly stopping and starting a timer churns memory (and potentially leaks it). - m_ignoreLogTimer = true; + m_LogTimer.Stop(); std::lock_guard lk(m_LogSection); while (!msgQueue.empty()) @@ -351,7 +346,7 @@ void CLogWindow::UpdateLog() msgQueue.pop(); } - m_ignoreLogTimer = false; + m_LogTimer.Start(); } void CLogWindow::Log(LogTypes::LOG_LEVELS level, const char *text) diff --git a/Source/Core/DolphinWX/LogWindow.h b/Source/Core/DolphinWX/LogWindow.h index eb126b8250..50ddf3cc44 100644 --- a/Source/Core/DolphinWX/LogWindow.h +++ b/Source/Core/DolphinWX/LogWindow.h @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -25,8 +26,6 @@ class wxBoxSizer; class wxCheckBox; class wxChoice; class wxTextCtrl; -class wxTimer; -class wxTimerEvent; // Uses multiple inheritance - only sane because LogListener is a pure virtual interface. class CLogWindow : public wxPanel, LogListener @@ -50,8 +49,7 @@ private: CFrame* Parent; wxFont DefaultFont, MonoSpaceFont; std::vector LogFont; - wxTimer* m_LogTimer; - bool m_ignoreLogTimer; + wxTimer m_LogTimer; LogManager* m_LogManager; std::queue > msgQueue; bool m_writeFile, m_writeWindow, m_writeDebugger, m_LogAccess;