Commit 46ec23e4 authored by Boudewijn Rempt's avatar Boudewijn Rempt

Check whether there's a context before accessing it

I doubt this helps with 408872, but it's a good idea to do in
any case.

CCBUG:408872
parent 30a93475
......@@ -149,15 +149,18 @@ void KisMirrorAxis::drawDecoration(QPainter& gc, const QRectF& updateArea, const
gc.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
QOpenGLContext *ctx = QOpenGLContext::currentContext();
bool hasMultisample = ((gc.paintEngine()->type() == QPaintEngine::OpenGL2) &&
(ctx->hasExtension("GL_ARB_multisample")));
// QPainter cannot anti-alias the edges of circles etc. when using OpenGL
// So instead, use native OpenGL anti-aliasing when available.
if (hasMultisample) {
gc.beginNativePainting();
ctx->functions()->glEnable(GL_MULTISAMPLE);
gc.endNativePainting();
bool hasMultisample = false;
if (ctx) {
hasMultisample = ((gc.paintEngine()->type() == QPaintEngine::OpenGL2) &&
(ctx->hasExtension("GL_ARB_multisample")));
// QPainter cannot anti-alias the edges of circles etc. when using OpenGL
// So instead, use native OpenGL anti-aliasing when available.
if (hasMultisample) {
gc.beginNativePainting();
ctx->functions()->glEnable(GL_MULTISAMPLE);
gc.endNativePainting();
}
}
float halfHandleSize = d->config.handleSize() / 2;
......@@ -166,8 +169,8 @@ void KisMirrorAxis::drawDecoration(QPainter& gc, const QRectF& updateArea, const
if(d->config.mirrorHorizontal() && !d->config.hideHorizontalDecoration()) {
if (!d->horizontalAxis.isNull()) {
// QPointF horizontalIndicatorCenter = d->horizontalAxis.unitVector().pointAt(15);
// QRectF horizontalIndicator = QRectF(horizontalIndicatorCenter.x() - halfHandleSize, horizontalIndicatorCenter.y() - halfHandleSize, d->config.handleSize(), d->config.handleSize());
// QPointF horizontalIndicatorCenter = d->horizontalAxis.unitVector().pointAt(15);
// QRectF horizontalIndicator = QRectF(horizontalIndicatorCenter.x() - halfHandleSize, horizontalIndicatorCenter.y() - halfHandleSize, d->config.handleSize(), d->config.handleSize());
float horizontalHandlePosition = qBound<float>(d->minHandlePosition, d->config.horizontalHandlePosition(), d->horizontalAxis.length() - d->minHandlePosition);
QPointF horizontalHandleCenter = d->horizontalAxis.unitVector().pointAt(horizontalHandlePosition);
......@@ -176,8 +179,8 @@ void KisMirrorAxis::drawDecoration(QPainter& gc, const QRectF& updateArea, const
gc.setPen(QPen(QColor(0, 0, 0, 64), 2, Qt::DashDotDotLine, Qt::RoundCap, Qt::RoundJoin));
gc.drawLine(d->horizontalAxis);
// gc.drawEllipse(horizontalIndicator);
// gc.drawPixmap(horizontalIndicator.adjusted(5, 5, -5, -5).toRect(), d->horizontalIcon);
// gc.drawEllipse(horizontalIndicator);
// gc.drawPixmap(horizontalIndicator.adjusted(5, 5, -5, -5).toRect(), d->horizontalIcon);
// don't draw the handles if we are locking the axis for movement
if (!d->config.lockHorizontal()) {
......@@ -198,8 +201,8 @@ void KisMirrorAxis::drawDecoration(QPainter& gc, const QRectF& updateArea, const
gc.drawLine(d->verticalAxis);
// QPointF verticalIndicatorCenter = d->verticalAxis.unitVector().pointAt(15);
// QRectF verticalIndicator = QRectF(verticalIndicatorCenter.x() - halfHandleSize, verticalIndicatorCenter.y() - halfHandleSize, d->config.handleSize(), d->config.handleSize());
// QPointF verticalIndicatorCenter = d->verticalAxis.unitVector().pointAt(15);
// QRectF verticalIndicator = QRectF(verticalIndicatorCenter.x() - halfHandleSize, verticalIndicatorCenter.y() - halfHandleSize, d->config.handleSize(), d->config.handleSize());
float verticalHandlePosition = qBound<float>(d->minHandlePosition, d->config.verticalHandlePosition(), d->verticalAxis.length() - d->minHandlePosition);
QPointF verticalHandleCenter = d->verticalAxis.unitVector().pointAt(verticalHandlePosition);
......@@ -232,7 +235,7 @@ bool KisMirrorAxis::eventFilter(QObject* target, QEvent* event)
if (!visible()) return false;
QObject *expectedCanvasWidget = view() ?
view()->canvasBase()->canvasWidget() : 0;
view()->canvasBase()->canvasWidget() : 0;
if (!expectedCanvasWidget || target != expectedCanvasWidget) return false;
......
......@@ -80,7 +80,9 @@ struct KisScreenInformationAdapter::Private
KisScreenInformationAdapter::KisScreenInformationAdapter(QOpenGLContext *context)
: m_d(new Private)
{
m_d->initialize(context);
if (context) {
m_d->initialize(context);
}
}
KisScreenInformationAdapter::~KisScreenInformationAdapter()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment