From 23a7f7ad21e9eba48123d978466c0a1eec4d2d06 Mon Sep 17 00:00:00 2001 From: "Jake.Stine" Date: Wed, 12 May 2010 13:58:10 +0000 Subject: [PATCH] * Likely fix for linux's crash-on-exit. * Fix for random crash when hot-swapping plugins from the config panel. git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2987 96395faa-99c1-11dd-bbfe-3dabce05a288 --- pcsx2/gui/App.h | 2 +- pcsx2/gui/AppInit.cpp | 20 ++++++++++++++++++++ pcsx2/gui/AppMain.cpp | 4 +++- pcsx2/gui/ConsoleLogger.cpp | 7 ------- pcsx2/gui/ConsoleLogger.h | 1 - pcsx2/gui/MainFrame.cpp | 6 ------ pcsx2/gui/MainFrame.h | 1 - pcsx2/gui/Panels/PluginSelectorPanel.cpp | 1 + 8 files changed, 25 insertions(+), 17 deletions(-) diff --git a/pcsx2/gui/App.h b/pcsx2/gui/App.h index b51ecacb66..9c31f57398 100644 --- a/pcsx2/gui/App.h +++ b/pcsx2/gui/App.h @@ -576,8 +576,8 @@ protected: void HandleEvent(wxEvtHandler* handler, wxEventFunction func, wxEvent& event); void OnEmuKeyDown( wxKeyEvent& evt ); - void OnSysExecutorTaskTimeout( wxTimerEvent& evt ); + void OnDestroyWindow( wxWindowDestroyEvent& evt ); // ---------------------------------------------------------------------------- // Override wx default exception handling behavior diff --git a/pcsx2/gui/AppInit.cpp b/pcsx2/gui/AppInit.cpp index 545f50b6dd..d20df5e550 100644 --- a/pcsx2/gui/AppInit.cpp +++ b/pcsx2/gui/AppInit.cpp @@ -426,6 +426,8 @@ bool Pcsx2App::OnInit() Connect( pxID_PadHandler_Keydown, wxEVT_KEY_DOWN, wxKeyEventHandler (Pcsx2App::OnEmuKeyDown) ); + Connect( wxEVT_DESTROY, wxWindowDestroyEventHandler (Pcsx2App::OnDestroyWindow) ); + // User/Admin Mode Dual Setup: // PCSX2 now supports two fundamental modes of operation. The default is Classic mode, // which uses the Current Working Directory (CWD) for all user data files, and requires @@ -554,6 +556,24 @@ int Pcsx2App::OnExit() return wxApp::OnExit(); } +void Pcsx2App::OnDestroyWindow( wxWindowDestroyEvent& evt ) +{ + // Precautions: + // * Whenever windows are destroyed, make sure to check if it matches our "active" + // console logger. If so, we need to disable logging to the console window, or else + // it'll crash. (this is because the console log system uses a cached window handle + // instead of looking the window up via it's ID -- fast but potentially unsafe). + // + // * The virtual machine's plugins usually depend on the GS window handle being valid, + // so if the GS window is the one being shut down then we need to make sure to close + // out the Corethread before it vanishes completely from existence. + + + OnProgramLogClosed( evt.GetId() ); + OnGsFrameClosed( evt.GetId() ); + evt.Skip(); +} + // -------------------------------------------------------------------------------------- // SysEventHandler // -------------------------------------------------------------------------------------- diff --git a/pcsx2/gui/AppMain.cpp b/pcsx2/gui/AppMain.cpp index a78c8ed2da..26845adcd2 100644 --- a/pcsx2/gui/AppMain.cpp +++ b/pcsx2/gui/AppMain.cpp @@ -816,8 +816,10 @@ void Pcsx2App::CloseGsPanel() } } -void Pcsx2App::OnGsFrameClosed() +void Pcsx2App::OnGsFrameClosed( wxWindowID id ) { + if( (m_id_GsFrame == wxID_ANY) || (m_id_GsFrame != id) ) return; + CoreThread.Suspend(); m_id_GsFrame = wxID_ANY; } diff --git a/pcsx2/gui/ConsoleLogger.cpp b/pcsx2/gui/ConsoleLogger.cpp index e15670547a..fa74046e61 100644 --- a/pcsx2/gui/ConsoleLogger.cpp +++ b/pcsx2/gui/ConsoleLogger.cpp @@ -313,7 +313,6 @@ ConsoleLogFrame::ConsoleLogFrame( MainEmuFrame *parent, const wxString& title, A Connect( m_item_StdoutIOP->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( ConsoleLogFrame::OnLogSourceChanged ) ); Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler (ConsoleLogFrame::OnCloseWindow) ); - Connect( wxEVT_DESTROY, wxWindowDestroyEventHandler (ConsoleLogFrame::OnDestroyWindow) ); Connect( wxEVT_MOVE, wxMoveEventHandler (ConsoleLogFrame::OnMoveAround) ); Connect( wxEVT_SIZE, wxSizeEventHandler (ConsoleLogFrame::OnResize) ); Connect( wxEVT_ACTIVATE, wxActivateEventHandler (ConsoleLogFrame::OnActivate) ); @@ -514,12 +513,6 @@ void ConsoleLogFrame::OnCloseWindow(wxCloseEvent& event) } } -void ConsoleLogFrame::OnDestroyWindow(wxWindowDestroyEvent& event) -{ - m_threadlogger = NULL; - wxGetApp().OnProgramLogClosed( GetId() ); -} - void ConsoleLogFrame::OnOpen(wxCommandEvent& WXUNUSED(event)) { Show(true); diff --git a/pcsx2/gui/ConsoleLogger.h b/pcsx2/gui/ConsoleLogger.h index d975f5652b..34574a55f9 100644 --- a/pcsx2/gui/ConsoleLogger.h +++ b/pcsx2/gui/ConsoleLogger.h @@ -250,7 +250,6 @@ protected: void OnLogSourceChanged(wxCommandEvent& event); virtual void OnCloseWindow(wxCloseEvent& event); - virtual void OnDestroyWindow(wxWindowDestroyEvent& event); void OnSetTitle( wxCommandEvent& event ); void OnDockedMove( wxCommandEvent& event ); diff --git a/pcsx2/gui/MainFrame.cpp b/pcsx2/gui/MainFrame.cpp index 327d6bf3f6..83749086af 100644 --- a/pcsx2/gui/MainFrame.cpp +++ b/pcsx2/gui/MainFrame.cpp @@ -105,11 +105,6 @@ void MainEmuFrame::OnCloseWindow(wxCloseEvent& evt) evt.Skip(); } -void MainEmuFrame::OnDestroyWindow( wxWindowDestroyEvent& evt ) -{ - evt.Skip(); -} - void MainEmuFrame::OnMoveAround( wxMoveEvent& evt ) { // Uncomment this when doing logger stress testing (and then move the window around @@ -468,7 +463,6 @@ MainEmuFrame::MainEmuFrame(wxWindow* parent, const wxString& title) ConnectMenus(); Connect( wxEVT_MOVE, wxMoveEventHandler (MainEmuFrame::OnMoveAround) ); Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler (MainEmuFrame::OnCloseWindow) ); - Connect( wxEVT_DESTROY, wxWindowDestroyEventHandler (MainEmuFrame::OnDestroyWindow) ); Connect( wxEVT_SET_FOCUS, wxFocusEventHandler (MainEmuFrame::OnFocus) ); diff --git a/pcsx2/gui/MainFrame.h b/pcsx2/gui/MainFrame.h index 4dfbd0b05b..f4e4dbbce0 100644 --- a/pcsx2/gui/MainFrame.h +++ b/pcsx2/gui/MainFrame.h @@ -157,7 +157,6 @@ protected: void InitLogBoxPosition( AppConfig::ConsoleLogOptions& conf ); void OnCloseWindow( wxCloseEvent& evt ); - void OnDestroyWindow( wxWindowDestroyEvent& evt ); void OnMoveAround( wxMoveEvent& evt ); void OnFocus( wxFocusEvent& evt ); void OnActivate( wxActivateEvent& evt ); diff --git a/pcsx2/gui/Panels/PluginSelectorPanel.cpp b/pcsx2/gui/Panels/PluginSelectorPanel.cpp index c21c469568..6d53d31770 100644 --- a/pcsx2/gui/Panels/PluginSelectorPanel.cpp +++ b/pcsx2/gui/Panels/PluginSelectorPanel.cpp @@ -271,6 +271,7 @@ void SysExecEvent_ApplyPlugins::InvokeEvent() CorePlugins.Shutdown(); CorePlugins.Unload(); LoadPluginsImmediate(); + CorePlugins.Init(); if( buffer ) CoreThread.UploadStateCopy( *buffer );