From fcf46a9f614efda3f0bfba38685d070f9a20fdfd Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sat, 17 Jul 2004 20:38:59 +0000 Subject: [PATCH] fix "pure virtual method called" on quit --- .../src/arch/MemoryCard/MemoryCardDriverThreaded.cpp | 11 ++++++++++- .../src/arch/MemoryCard/MemoryCardDriverThreaded.h | 1 + .../MemoryCard/MemoryCardDriverThreaded_Linux.cpp | 5 +++++ .../arch/MemoryCard/MemoryCardDriverThreaded_Linux.h | 1 + .../MemoryCard/MemoryCardDriverThreaded_Windows.cpp | 5 +++++ .../MemoryCard/MemoryCardDriverThreaded_Windows.h | 1 + 6 files changed, 23 insertions(+), 1 deletion(-) diff --git a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded.cpp b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded.cpp index 9c90fe362d..9faf5d161b 100644 --- a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded.cpp +++ b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded.cpp @@ -34,7 +34,7 @@ void MemoryCardDriverThreaded::StartThread() m_threadMemoryCardMount.Create( MountThread_Start, this ); } -MemoryCardDriverThreaded::~MemoryCardDriverThreaded() +void MemoryCardDriverThreaded::StopThread() { m_bShutdownNextUpdate = true; LOG->Trace( "Shutting down Mount thread..." ); @@ -42,6 +42,15 @@ MemoryCardDriverThreaded::~MemoryCardDriverThreaded() LOG->Trace( "Mount thread shut down." ); } +MemoryCardDriverThreaded::~MemoryCardDriverThreaded() +{ + /* Must call StopThread from the derived destructor. Otherwise, we can + * call MountThreadDoOneUpdate from the thread after the derived dtor, + * which means that function is now virtual, and we'll crash with "pure + * virtual method called". */ + ASSERT( !m_threadMemoryCardMount.IsCreated() ); +} + void MemoryCardDriverThreaded::PauseMountingThread() { m_mutexPause.Lock(); diff --git a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded.h b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded.h index d43aa5b9ec..fb85abe75d 100644 --- a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded.h +++ b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded.h @@ -42,6 +42,7 @@ private: protected: void StartThread(); // call this in the derived constructor to start the mounting thread + void StopThread(); // call this in the derived desstructor to stop the mounting thread virtual void MountThreadDoOneUpdate() = 0; // this will get called as fast as possible virtual void Mount( UsbStorageDevice* pDevice, CString sMountPoint ) = 0; diff --git a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.cpp b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.cpp index 8e4c2d0344..f4fc5c7ead 100644 --- a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.cpp +++ b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.cpp @@ -136,6 +136,11 @@ MemoryCardDriverThreaded_Linux::MemoryCardDriverThreaded_Linux() this->StartThread(); } +MemoryCardDriverThreaded_Linux::~MemoryCardDriverThreaded_Linux() +{ + this->StopThread(); +} + void MemoryCardDriverThreaded_Linux::ResetUsbStorage() { // diff --git a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.h b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.h index c96e044035..17f3bf04d0 100644 --- a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.h +++ b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Linux.h @@ -7,6 +7,7 @@ class MemoryCardDriverThreaded_Linux : public MemoryCardDriverThreaded { public: MemoryCardDriverThreaded_Linux(); + virtual ~MemoryCardDriverThreaded_Linux(); virtual void Unmount( UsbStorageDevice* pDevice, CString sMountPoint ); virtual void Flush( UsbStorageDevice* pDevice ); diff --git a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Windows.cpp b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Windows.cpp index 78f8cbc24d..b88b01a739 100644 --- a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Windows.cpp +++ b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Windows.cpp @@ -18,6 +18,11 @@ MemoryCardDriverThreaded_Windows::MemoryCardDriverThreaded_Windows() StartThread(); } +MemoryCardDriverThreaded_Windows::~MemoryCardDriverThreaded_Windows() +{ + StopThread(); +} + typedef const CString& CCStringRef; static bool TestReady( CCStringRef sDrive ) diff --git a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Windows.h b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Windows.h index 374856d39e..cb8c9a14c2 100644 --- a/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Windows.h +++ b/stepmania/src/arch/MemoryCard/MemoryCardDriverThreaded_Windows.h @@ -8,6 +8,7 @@ class MemoryCardDriverThreaded_Windows : public MemoryCardDriverThreaded { public: MemoryCardDriverThreaded_Windows(); + virtual ~MemoryCardDriverThreaded_Windows(); virtual void Unmount( UsbStorageDevice* pDevice, CString sMountPoint ); virtual void Flush( UsbStorageDevice* pDevice );