Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Bug in my code causing crash Qt Spectrogram



  • Here is the code I believe is suspect as there is a direct reference to Line 45 in my showpeak function in the call stack.

    void ShowPeak::updatePeak()
    {
    m_peak = QPointF(0, -100000);

    QXYSeries* series = static_cast<QXYSeries*>(m_chart->series()[0]);
    QValueAxis* axisX = static_cast<QValueAxis*>(m_chart->axisX(series));
    
    for (const QPointF& p : series->pointsVector())
    {
        if (p.y() > m_peak.y()
            && p.x() >= axisX->min()
            && p.x() <= axisX->max())
        {
            m_peak = p;
        }
    }
    

    }

    I am using multithreading, but I am not sure what exactly is causing my project to fail. The error code is:

    Exception thrown: read access violation.
    _Tgt was 0x2990070.

    Many thanks to anyone who can provide any insight.

    J

    0_1531963852045_atomic_error.PNG

    0_1531963836694_Capture.PNG


  • Lifetime Qt Champion

    @Yippiyak

    ... and line 45 is which one?

    thanks



  • @aha_1980
    for (const QPointF& p : series->pointsVector())


  • Lifetime Qt Champion

    Hi,

    Are you sure that this pointer is valid ?
    Also, you should rather use dynamic_cast (or qobject_cast if it’s for a QObject based class) and check the returned value against null_ptr.


Log in to reply