Fix for video-related crashing on Windows

Issue observed was that OpenBoard would crash on some Windows systems
when a video was on the page and that page was saved (due to switching
to document mode, auto saving, or duplicating the page), or when cutting
the video with Ctrl-X.

This was due to QTBUG-32522, where setting the video output for a
QMediaPlayer that is hidden results in a crash.

This commit is a work-around for this Qt issue, and so should be reverted
if and when the upstream issue is fixed.
preferencesAboutTextFull
Craig Watson 7 years ago
parent 83874ddb08
commit 5416e6d834
  1. 39
      src/domain/UBGraphicsMediaItem.cpp
  2. 3
      src/domain/UBGraphicsMediaItem.h

@ -130,7 +130,14 @@ UBGraphicsVideoItem::UBGraphicsVideoItem(const QUrl &pMediaFileUrl, QGraphicsIte
mVideoItem->setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object);
mVideoItem->setFlag(ItemStacksBehindParent, true);
mMediaObject->setVideoOutput(mVideoItem);
/* setVideoOutput has to be called only when the video item is visible on the screen,
* due to a Qt bug (QTBUG-32522). So instead of calling it here, it is called when the
* active scene has changed, or when the item is first created.
* If and when Qt fix this issue, this should be changed back.
* */
//mMediaObject->setVideoOutput(mVideoItem);
mHasVideoOutput = false;
mMediaObject->setNotifyInterval(50);
setMinimumSize(QSize(320, 240));
@ -155,8 +162,10 @@ UBGraphicsVideoItem::UBGraphicsVideoItem(const QUrl &pMediaFileUrl, QGraphicsIte
UBGraphicsMediaItem::~UBGraphicsMediaItem()
{
if (mMediaObject)
if (mMediaObject) {
mMediaObject->stop();
delete mMediaObject;
}
}
QVariant UBGraphicsMediaItem::itemChange(GraphicsItemChange change, const QVariant &value)
@ -569,6 +578,22 @@ void UBGraphicsVideoItem::paint(QPainter *painter, const QStyleOptionGraphicsIte
}
QVariant UBGraphicsVideoItem::itemChange(GraphicsItemChange change, const QVariant &value) {
if (change == QGraphicsItem::ItemVisibleChange
&& value.toBool()
&& !mHasVideoOutput
&& UBApplication::app()->boardController
&& UBApplication::app()->boardController->activeScene() == scene())
{
//qDebug() << "Item change, setting video output";
mMediaObject->setVideoOutput(mVideoItem);
mHasVideoOutput = true;
}
return UBGraphicsMediaItem::itemChange(change, value);
}
void UBGraphicsVideoItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
// Display the seek bar
@ -610,9 +635,19 @@ void UBGraphicsVideoItem::mediaStateChanged(QMediaPlayer::State state)
void UBGraphicsVideoItem::activeSceneChanged()
{
//qDebug() << "Active scene changed";
// Update the visibility of the placeholder, to prevent it being hidden when switching pages
setPlaceholderVisible(!mErrorString.isEmpty());
// Call setVideoOutput, if the video is visible and if it hasn't been called already
if (!mHasVideoOutput && UBApplication::boardController->activeScene() == scene()) {
//qDebug() << "setting video output";
mMediaObject->setMedia(mMediaFileUrl);
mMediaObject->setVideoOutput(mVideoItem);
mHasVideoOutput = true;
}
UBGraphicsMediaItem::activeSceneChanged();
}

@ -207,11 +207,14 @@ protected:
QGraphicsVideoItem *mVideoItem;
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
void setPlaceholderVisible(bool visible);
bool mHasVideoOutput;
};

Loading…
Cancel
Save