diff data/fft/FFTFileCache.cpp @ 455:3e0f1f7bec85

* Fix a nasty and long-standing race condition in MatrixFile's use of FileReadThread that was causing crashes sometimes
author Chris Cannam
date Thu, 09 Oct 2008 20:10:28 +0000
parents 115f60df1e4d
children f60360209e5c
line wrap: on
line diff
--- a/data/fft/FFTFileCache.cpp	Thu Oct 09 13:13:33 2008 +0000
+++ b/data/fft/FFTFileCache.cpp	Thu Oct 09 20:10:28 2008 +0000
@@ -19,6 +19,7 @@
 
 #include "base/Profiler.h"
 #include "base/Thread.h"
+#include "base/Exceptions.h"
 
 #include <iostream>
 
@@ -308,13 +309,19 @@
     if (!m_readbuf) {
         m_readbuf = new char[m_mfc->getHeight() * 2 * m_mfc->getCellSize()];
     }
-    m_mfc->getColumnAt(x, m_readbuf);
-    if (m_mfc->haveSetColumnAt(x + 1)) {
-        m_mfc->getColumnAt
-            (x + 1, m_readbuf + m_mfc->getCellSize() * m_mfc->getHeight());
-        m_readbufWidth = 2;
-    } else {
-        m_readbufWidth = 1;
+    try {
+        m_mfc->getColumnAt(x, m_readbuf);
+        if (m_mfc->haveSetColumnAt(x + 1)) {
+            m_mfc->getColumnAt
+                (x + 1, m_readbuf + m_mfc->getCellSize() * m_mfc->getHeight());
+            m_readbufWidth = 2;
+        } else {
+            m_readbufWidth = 1;
+        }
+    } catch (FileReadFailed f) {
+        std::cerr << "ERROR: FFTFileCache::populateReadBuf: File read failed: "
+                  << f.what() << std::endl;
+        memset(m_readbuf, 0, m_mfc->getHeight() * 2 * m_mfc->getCellSize());
     }
     m_readbufCol = x;
 }