Leo
Leo

Reputation: 1139

Heap block modified past requested size

Update : The error seems to be generated by this line: *line = color;

I get the following error but I don't understand where it can come from:

The error:

HEAP[testQt.exe]: Heap block at 0B444FE8 modified at 0B44C6B0 past requested size of 76c0

The line that generates it:

return QPixmap::fromImage(qimage);

From:

QPixmap Interpolation::getData() {
    QPointF pt(0, 0);
    QRgb color;
    QImage qimage(m_width, m_height, QImage::Format_ARGB32);
    qimage.fill(Qt::transparent);

    for (int i(0); i < m_height; ++i) {
        m_progress->setValue(m_width+i);
        QRgb *line = (QRgb *)qimage.scanLine(i);
        for (int j(0); j < m_width; ++j) {
            pt.setX(j);
            pt.setY(i);
            line += 1;
            if (isInHull(pt)) {
                color = colorScale(interp(&pt));
                *line = color; //If I remove this part the program won't crash
            }
        }
    }  
    return QPixmap::fromImage(qimage);
}

If it helps:

QRgb Interpolation::colorScale(qreal value)
{
    int cat;
    cat = qFloor(qreal(9)*(value-m_min)/(m_max-m_min));

    return m_couleurs[cat];
}

with:

m_couleurs[0] = qRgb(247, 252, 240);
m_couleurs[1] = qRgb(224, 243, 219);
m_couleurs[2] = qRgb(204, 235, 197);
m_couleurs[3] = qRgb(168, 221, 181);
m_couleurs[4] = qRgb(123, 204, 196);
m_couleurs[5] = qRgb(78, 179, 211);
m_couleurs[6] = qRgb(43, 140, 190);
m_couleurs[7] = qRgb(8, 104, 172);
m_couleurs[8] = qRgb(8, 64, 129);

Any lead would be appreciated.

Edit: added the full function in case it helps. Edit2: made the code more clear and removed the useless parts. Edit3: updated the question.

Upvotes: 0

Views: 15632

Answers (1)

Rafael Baptista
Rafael Baptista

Reputation: 11499

You advance line before you assign color to *line. So when j = 0, you're actually setting pixel 1, at the end of the last pixel on the last scan line you write past the end of the buffer.

Move line += 1 to the end of the loop.

Upvotes: 6

Related Questions