diff --git a/src/IshmaelDetector/EnergySumProcess.java b/src/IshmaelDetector/EnergySumProcess.java index 0aa1b990..bec3dfb7 100644 --- a/src/IshmaelDetector/EnergySumProcess.java +++ b/src/IshmaelDetector/EnergySumProcess.java @@ -79,8 +79,9 @@ public class EnergySumProcess extends IshDetFnProcess { EnergySumParams p = (EnergySumParams)ishDetControl.ishDetParams; PamDataBlock inputDataBlock = getInputDataBlock(); //might be null - if (inputDataBlock != null && inputDataBlock.getUnitsCount() > 0) { - savedGramHeight = ((FFTDataUnit)inputDataBlock.getLastUnit()).getFftData().length(); + FFTDataUnit lastFFTUnit = ((FFTDataUnit)inputDataBlock.getLastUnit()); + if (lastFFTUnit != null) { + savedGramHeight = lastFFTUnit.getFftData().length(); int len = savedGramHeight; //Should be max(1,...) here, but FFT bin 0 has 0's in it. loBin = Math.max(1, (int) Math.floor(len * p.f0 / (sampleRate/2))); diff --git a/src/IshmaelDetector/SgramCorrProcess.java b/src/IshmaelDetector/SgramCorrProcess.java index 0be85eea..fe7de69a 100644 --- a/src/IshmaelDetector/SgramCorrProcess.java +++ b/src/IshmaelDetector/SgramCorrProcess.java @@ -83,9 +83,14 @@ public class SgramCorrProcess extends IshDetFnProcess protected void prepareMyParams() { SgramCorrParams p = (SgramCorrParams)ishDetControl.ishDetParams; PamDataBlock inputDataBlock = getInputDataBlock(); - - if (inputDataBlock != null && inputDataBlock.getUnitsCount() > 0) { - savedGramHeight = ((FFTDataUnit)inputDataBlock.getLastUnit()).getFftData().length(); + /* + * get the unit. first, then check it's null. Due to multithreading it's + * possible that checking there are units and then asking for one,without + * synchronization will crash if the unit is deleted between those two calls. + */ + FFTDataUnit lastFFTUnit = ((FFTDataUnit)inputDataBlock.getLastUnit()); + if (lastFFTUnit != null) { + savedGramHeight = lastFFTUnit.getFftData().length(); /* * fft information is now stored in an FFTDataBLock, so no need to get * back to the process above it.