mirror of
https://github.com/gqrx-sdr/gqrx.git
synced 2024-09-21 10:47:10 +00:00
Fix hangs and segfaults when the FFT is moved around and zoomed
Moving the FFT plot off the screen caused a hang or a segfault. Making the window too large caused segfaults because MAX_SCREENSIZE and HORZ_DIVS_MAX were not taken into account. The zoom could also become negative or get stuck on max.
This commit is contained in:
parent
29d6c1883f
commit
ce8ac8900f
@ -244,7 +244,7 @@ void CPlotter::mouseMoveEvent(QMouseEvent* event)
|
||||
}
|
||||
else
|
||||
{
|
||||
m_FftCenter += delta_hz;
|
||||
setFftCenterFreq(m_FftCenter + delta_hz);
|
||||
}
|
||||
if (m_Running)
|
||||
m_DrawOverlay = true;
|
||||
@ -474,7 +474,7 @@ void CPlotter::wheelEvent(QWheelEvent * event)
|
||||
{
|
||||
// calculate new range shown on FFT
|
||||
float zoom_factor = event->delta() < 0 ? 1.1 : 0.9;
|
||||
float new_range = (float)(m_Span) * zoom_factor;
|
||||
float new_range = qMax((float)(m_Span) * zoom_factor, 10.0f);
|
||||
|
||||
// Frequency where event occured is kept fixed under mouse
|
||||
float ratio = (float)pt.x() / (float)m_OverlayPixmap.width();
|
||||
@ -591,7 +591,7 @@ void CPlotter::draw()
|
||||
|
||||
QPainter painter1(&m_WaterfallPixmap);
|
||||
// get scaled FFT data
|
||||
getScreenIntegerFFTData(255, w, m_MaxdB, m_MindB,
|
||||
getScreenIntegerFFTData(255, qMin(w, MAX_SCREENSIZE), m_MaxdB, m_MindB,
|
||||
m_FftCenter-m_Span/2, m_FftCenter+m_Span/2,
|
||||
m_wfData, m_fftbuf, &xmin, &xmax);
|
||||
|
||||
@ -620,7 +620,7 @@ void CPlotter::draw()
|
||||
QPainter painter2(&m_2DPixmap);
|
||||
|
||||
// get new scaled fft data
|
||||
getScreenIntegerFFTData(h, w, m_MaxdB, m_MindB,
|
||||
getScreenIntegerFFTData(h, qMin(w, MAX_SCREENSIZE), m_MaxdB, m_MindB,
|
||||
m_FftCenter-m_Span/2, m_FftCenter+m_Span/2,
|
||||
m_fftData, m_fftbuf, &xmin, &xmax);
|
||||
|
||||
@ -864,7 +864,7 @@ void CPlotter::drawOverlay()
|
||||
|
||||
// horizontal grids (size and grid calcs could be moved to resize)
|
||||
m_VerDivs = h/m_VdivDelta+1;
|
||||
m_HorDivs = w/m_HdivDelta;
|
||||
m_HorDivs = qMin(w/m_HdivDelta, HORZ_DIVS_MAX);
|
||||
if (m_HorDivs % 2)
|
||||
m_HorDivs++; // we want an odd number of divs so that we have a center line
|
||||
|
||||
|
@ -66,7 +66,10 @@ public:
|
||||
/* Shown bandwidth around SetCenterFreq() */
|
||||
void setSpanFreq(quint32 s)
|
||||
{
|
||||
if (s > 0 && s < INT_MAX) {
|
||||
m_Span = (qint32)s;
|
||||
setFftCenterFreq(m_FftCenter);
|
||||
}
|
||||
drawOverlay();
|
||||
}
|
||||
void updateOverlay() { drawOverlay(); }
|
||||
@ -96,7 +99,10 @@ public:
|
||||
return m_SampleFreq;
|
||||
}
|
||||
|
||||
void setFftCenterFreq(qint64 f) { m_FftCenter = f; }
|
||||
void setFftCenterFreq(qint64 f) {
|
||||
qint64 limit = ((qint64)m_SampleFreq + m_Span) / 2 - 1;
|
||||
m_FftCenter = qBound(-limit, f, limit);
|
||||
}
|
||||
|
||||
signals:
|
||||
void newCenterFreq(qint64 f);
|
||||
|
Loading…
Reference in New Issue
Block a user