Skip to content

Commit 0a77257

Browse files
committed
Fix crash during OpenGL initialization in PenLayer
1 parent a6cba31 commit 0a77257

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/penlayer.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ PenLayer::PenLayer(QNanoQuickItem *parent) :
1313
{
1414
m_fboFormat.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
1515
m_fboFormat.setSamples(m_antialiasingEnabled ? 4 : 0);
16-
17-
m_glF.initializeOpenGLFunctions();
1816
}
1917

2018
PenLayer::~PenLayer()
@@ -66,11 +64,16 @@ void scratchcpprender::PenLayer::clear()
6664
if (!m_fbo)
6765
return;
6866

67+
if (!m_glF) {
68+
m_glF = std::make_unique<QOpenGLFunctions>();
69+
m_glF->initializeOpenGLFunctions();
70+
}
71+
6972
m_fbo->bind();
70-
m_glF.glDisable(GL_SCISSOR_TEST);
71-
m_glF.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
72-
m_glF.glClear(GL_COLOR_BUFFER_BIT);
73-
m_glF.glEnable(GL_SCISSOR_TEST);
73+
m_glF->glDisable(GL_SCISSOR_TEST);
74+
m_glF->glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
75+
m_glF->glClear(GL_COLOR_BUFFER_BIT);
76+
m_glF->glEnable(GL_SCISSOR_TEST);
7477
m_fbo->release();
7578

7679
update();

src/penlayer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class PenLayer : public IPenLayer
5050
std::unique_ptr<QOpenGLFramebufferObject> m_fbo;
5151
std::unique_ptr<QOpenGLPaintDevice> m_paintDevice;
5252
QOpenGLFramebufferObjectFormat m_fboFormat;
53-
QOpenGLFunctions m_glF;
53+
std::unique_ptr<QOpenGLFunctions> m_glF;
5454
};
5555

5656
} // namespace scratchcpprender

0 commit comments

Comments
 (0)