diff --git a/src/graph_spectrum.js b/src/graph_spectrum.js index fc5db706..2f4b5c75 100644 --- a/src/graph_spectrum.js +++ b/src/graph_spectrum.js @@ -17,14 +17,14 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) { let that = this, analyserZoomX = 1.0 /* 100% */, analyserZoomY = 1.0 /* 100% */, + dataReload = false, + fftData = null, + prefs = new PrefStorage(), dataBuffer = { fieldIndex: 0, - curve: 0, + curve: null, fieldName: null, - }, - dataReload = false, - fftData = null, - prefs = new PrefStorage(); + }; try { let isFullscreen = false; @@ -128,11 +128,9 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) { analyser on screen*/ this.plotSpectrum = function (fieldIndex, curve, fieldName) { // Store the data pointers - dataBuffer = { - fieldIndex: fieldIndex, - curve: curve, - fieldName: fieldName, - }; + dataBuffer.fieldIndex = fieldIndex; + dataBuffer.curve = curve; + dataBuffer.fieldName = fieldName; // Detect change of selected field.... reload and redraw required. if (fftData == null || fieldIndex != fftData.fieldIndex || dataReload) { @@ -208,6 +206,13 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) { userSettings.spectrumType = optionSelected; saveOneUserSetting("spectrumType", userSettings.spectrumType); + // Restore dataBuffer if it was corrupted + if (!dataBuffer.curve) { + dataBuffer.curve = GraphSpectrumCalc._dataBuffer.curve; + dataBuffer.fieldName = GraphSpectrumCalc._dataBuffer.fieldName; + dataBuffer.fieldIndex = GraphSpectrumCalc._dataBuffer.fieldIndex; + console.warn("The dataBuffer was corrupted (set to default zeroes) in FlightLogAnalyser.spectrumTypeElem.change event"); + } // Recalculate the data, for the same curve than now, and draw it dataReload = true; that.plotSpectrum( diff --git a/src/graph_spectrum_calc.js b/src/graph_spectrum_calc.js index 84cd6758..14e51eec 100644 --- a/src/graph_spectrum_calc.js +++ b/src/graph_spectrum_calc.js @@ -29,7 +29,7 @@ export const GraphSpectrumCalc = { _blackBoxRate : 0, _dataBuffer : { fieldIndex: 0, - curve: 0, + curve: null, fieldName: null, }, _flightLog : null, @@ -85,7 +85,9 @@ GraphSpectrumCalc.setOutTime = function(time) { }; GraphSpectrumCalc.setDataBuffer = function(dataBuffer) { - this._dataBuffer = dataBuffer; + this._dataBuffer.curve = dataBuffer.curve; + this._dataBuffer.fieldName = dataBuffer.fieldName; + this._dataBuffer.fieldIndex = dataBuffer.fieldIndex; return undefined; };