From c6726d64a692904a0e003eaa8d3104feef9f64bd Mon Sep 17 00:00:00 2001 From: tomas-nestorovic Date: Fri, 11 Feb 2022 15:02:45 +0100 Subject: [PATCH] [#40] Track Map: General improvements and bugfixes (Part 26: Fixed responsiveness of context menu) --- Main/src/Image.cpp | 7 +++++-- Main/src/Image.h | 3 +++ Main/src/TdiTemplate.cpp | 3 +++ Main/src/ViewTrackMap.cpp | 8 +++++--- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Main/src/Image.cpp b/Main/src/Image.cpp index 0f6ce5ec..525553af 100644 --- a/Main/src/Image.cpp +++ b/Main/src/Image.cpp @@ -855,10 +855,13 @@ namespace Medium{ BOOL CImage::CanCloseFrame(CFrameWnd* pFrame){ // True <=> the MainWindow can be closed (and thus the application), otherwise False - EXCLUSIVELY_LOCK_THIS_IMAGE(); + PREVENT_FROM_DESTRUCTION(*this); + //EXCLUSIVELY_LOCK_THIS_IMAGE(); // commented out as it's being not worked with the Image // - first asking the DOS that handles this Image if (!dos->CanBeShutDown(pFrame)) return FALSE; // - then attempting to close this Image - return __super::CanCloseFrame(pFrame); + return pFrame!=nullptr // Null if e.g. app closing + ? __super::CanCloseFrame(pFrame) + : SaveModified(); } diff --git a/Main/src/Image.h b/Main/src/Image.h index 608a406c..4481a74d 100644 --- a/Main/src/Image.h +++ b/Main/src/Image.h @@ -623,6 +623,7 @@ static Utils::CPtrList Known; // list of known Images (registered in CRideApp::InitInstance) static Utils::CPtrList Devices; // list of known Devices (registered in CRideApp::InitInstance) + static CMutex destructionLocker; static CImage *GetActive(); static PCProperties DetermineType(LPCTSTR fileName); @@ -693,4 +694,6 @@ #define EXCLUSIVELY_LOCK_IMAGE(rImg) EXCLUSIVELY_LOCK(rImg) #define EXCLUSIVELY_LOCK_THIS_IMAGE() EXCLUSIVELY_LOCK_IMAGE(*this) + #define PREVENT_FROM_DESTRUCTION(rObj) const Utils::CExclusivelyLocked locker( (rObj).destructionLocker ) + #endif // IMAGE_H diff --git a/Main/src/TdiTemplate.cpp b/Main/src/TdiTemplate.cpp index 6f327633..12a31414 100644 --- a/Main/src/TdiTemplate.cpp +++ b/Main/src/TdiTemplate.cpp @@ -35,6 +35,8 @@ return m_pOnlyDoc; } + CMutex CImage::destructionLocker; + bool CMainWindow::CTdiTemplate::__closeDocument__(){ // closes the main Image (usually a disk) if (m_pOnlyDoc){ @@ -45,6 +47,7 @@ ( (CFrameWnd *)app.m_pMainWnd )->OnUpdateFrameTitle(FALSE); // updating the MainWindow's title (now without document) } const PImage image=(PImage)m_pOnlyDoc; + PREVENT_FROM_DESTRUCTION(*image); // have exlusive rights for destruction image->locker.Lock(); // have exclusive right for manipulation if (image->dos) delete image->dos, image->dos=nullptr; diff --git a/Main/src/ViewTrackMap.cpp b/Main/src/ViewTrackMap.cpp index 9718b8de..f7c9e8ca 100644 --- a/Main/src/ViewTrackMap.cpp +++ b/Main/src/ViewTrackMap.cpp @@ -231,7 +231,7 @@ break; const div_t d=div(trackNumber,nHeads); // . scanning the Track to draw its Sector Statuses - { EXCLUSIVELY_LOCK_IMAGE(*image); + { PREVENT_FROM_DESTRUCTION(*image); if (!::IsWindow(pvtm->m_hWnd)) // TrackMap may not exist if, for instance, switched to another view while still scanning some Track(s) continue; ti.cylinder=d.quot, ti.head=d.rem; @@ -241,7 +241,7 @@ // . scanning the Track to draw its Sector data if (pvtm->displayType>=TDisplayType::DATA_OK_ONLY){ TFdcStatus statuses[(TSector)-1]; - EXCLUSIVELY_LOCK_IMAGE(*image); + PREVENT_FROM_DESTRUCTION(*image); if (!::IsWindow(pvtm->m_hWnd)) // TrackMap may not exist if, for instance, switched to another view while still scanning some Track(s) continue; image->GetTrackData( ti.cylinder, ti.head, Revolution::CURRENT, ti.bufferId, sectorIdAndPositionIdentity, ti.nSectors, ti.bufferSectorData, ti.bufferLength, statuses ); @@ -522,6 +522,8 @@ rOutNanoseconds= ns<=longestTrackNanoseconds ? ns : -1; } // . determining the Sector on which the cursor hovers + if (point.xReadTrack( chs.cylinder, chs.head )) + if (IMAGE->WriteTrack(0,0,CImage::CTrackReaderWriter::Invalid)!=ERROR_NOT_SUPPORTED) // determining existence of low-level information by an attempt of writing mnu.EnableMenuItem( ID_HEAD, MF_BYCOMMAND|MF_ENABLED ); break; default: