c++ - QOpenGLWidget move context to another thread crash -
i have simple example , program crashed when tried call context()->movetothread(render_thread_);
. can help?
class framerenderer: public qthread { q_object public: framerenderer(qglcanvas *parent):m_parent(parent), qthread(){} void run() q_decl_override; qglcanvas *m_parent; }; class qglcanvas : public qopenglwidget, protected qopenglfunctions { q_object public: qglcanvas(qwidget* parent = null); ~qglcanvas(); virtual void initializegl(); virtual void paintgl(); virtual void resizegl(int width, int height); void drawthreadentry(); framerenderer* render_thread_; }; void framerenderer::run() { m_parent->drawthreadentry(); } qglcanvas::qglcanvas(qwidget* parent) : qopenglwidget(parent) { render_thread_ = new framerenderer(this); donecurrent(); context()->movetothread(render_thread_); render_thread_->start(); } void qglcanvas::drawthreadentry() { while(true) { makecurrent(); qopenglfunctions f; f.initializeopenglfunctions(); f.glclearcolor(1.0, 1.0, 1.0, 1.0); f.glfinish(); donecurrent(); emit update(); } }
i don't know if it's solution got similar problem on ios, context available after short period of time.
you can try add timmer , delay call opengl
.h
slots: void update();
.cpp
qtimer *timer = new qtimer(this); connect(timer, signal(timeout()), this, slot(update())); timer->start(1000);
if it's working maybe should try if can move tothread inside void qopenglwidget::initializegl() responsible set context
Comments
Post a Comment