I forgot that the QImage
, when given pixel data, is a shallow copy, not a deep one. The problem is fixed by keeping the actual frame data allocated as long as the QImage exists, like so:
void QGLCanvas::setFrame(const std::shared_ptr<VideoFrame>& newFrame)
{
// Keep the QGL canvas from drawing while we change the image
lock_guard<mutex> pixelLock(pixelsMutex);
// Keep a shared_ptr reference to our frame data
frame = newFrame;
// Create a new QImage, which is just a shallow copy of the frame.
img.reset(new QImage(frame->getPixels(),
frame->getWidth(),
frame->getHeight(),
QImage::Format_RGB888));
}