QT UI multi-thread issue.
-
wrote on 16 Oct 2017, 09:04 last edited by
Hi all ,
I have a multi-thread process , and use 1 thread to process QT UI . Then I use another thread to render OpenGL Texture .
Here is a question , sometimes 2 OpenGL(QT UI and OpenGL Texture) will conflict cause broken textures.like attaches.
this is normal UI ,
and
it broken textures when conflict happens.can someone give an answer to fix this issue , or a direction to survey , or go to other Forum.
Thanks all.
BR, -
Hi and welcome to devnet,
You should add the version of Qt you are using, the platform you are on and possibly the relevant code sources. It's impossible to give any good answers without knowing what you are currently doing.
-
Hi all ,
I have a multi-thread process , and use 1 thread to process QT UI . Then I use another thread to render OpenGL Texture .
Here is a question , sometimes 2 OpenGL(QT UI and OpenGL Texture) will conflict cause broken textures.like attaches.
this is normal UI ,
and
it broken textures when conflict happens.can someone give an answer to fix this issue , or a direction to survey , or go to other Forum.
Thanks all.
BR,wrote on 16 Oct 2017, 23:03 last edited by@TL_Tsai Are you properly protecting memory shared between threads? If you are potentially writing at the same time that will cause issues, usually a crash.
Make sure you protect your shared memory via mutexes like QMutex.
-
Hi and welcome to devnet,
You should add the version of Qt you are using, the platform you are on and possibly the relevant code sources. It's impossible to give any good answers without knowing what you are currently doing.
wrote on 17 Oct 2017, 03:55 last edited by@SGaist
My QT version is 5.9.1 , on Windows and with OpenVR library .
But about detail codes , I can't tell too much because company's policy.
Maybe I can show code about how I implement QT in or UI , but need times.still thanks your replying.
-
Hi and welcome to devnet,
You should add the version of Qt you are using, the platform you are on and possibly the relevant code sources. It's impossible to give any good answers without knowing what you are currently doing.
wrote on 17 Oct 2017, 12:01 last edited by@SGaist
hello , there is some codes ,
I declare QOpenGLContext and QQuickRenderControl and QOpenGLFramebufferObject in my header file
as below
QOpenGLContext *qOpenGLContext_;
QOpenGLFramebufferObject *qOpenglFramebufferObject;
QQuickRenderControl *qQuickRenderControl_and use a timer to call render() periodically
GLuint render () {
qQuickRenderControl_->polishItems();
qQuickRenderControl_->sync();
qQuickRenderControl_->render();
GLuint glTexture = qOpenglFramebufferObject->texture();
qOpenGLContext_->functions()->glFlush();
return glTexture;
}How do I improve my code? add mutex or...
thanks for your watching.
-
That's a bit not enough, you wrote about multiple threads yet here we only have a really small part that might not reflect at all the complexity of your application.
-
@SGaist
hello , there is some codes ,
I declare QOpenGLContext and QQuickRenderControl and QOpenGLFramebufferObject in my header file
as below
QOpenGLContext *qOpenGLContext_;
QOpenGLFramebufferObject *qOpenglFramebufferObject;
QQuickRenderControl *qQuickRenderControl_and use a timer to call render() periodically
GLuint render () {
qQuickRenderControl_->polishItems();
qQuickRenderControl_->sync();
qQuickRenderControl_->render();
GLuint glTexture = qOpenglFramebufferObject->texture();
qOpenGLContext_->functions()->glFlush();
return glTexture;
}How do I improve my code? add mutex or...
thanks for your watching.
wrote on 17 Oct 2017, 22:55 last edited by@TL_Tsai From what I see you have shared memory with no mutexing there. qOpenGlContext_, qQuickRenderControl_, and qOpenglFramebufferObject should probably all be mutexed if they are shared between threads.
Check out QMutex for an easy to use Qt mutex class. You can also use pure c++ mutexes if you'd like. Personally I would go with QMutex since you are already using Qt and it's better. ;)
-
@TL_Tsai From what I see you have shared memory with no mutexing there. qOpenGlContext_, qQuickRenderControl_, and qOpenglFramebufferObject should probably all be mutexed if they are shared between threads.
Check out QMutex for an easy to use Qt mutex class. You can also use pure c++ mutexes if you'd like. Personally I would go with QMutex since you are already using Qt and it's better. ;)
wrote on 18 Oct 2017, 03:57 last edited by TL_Tsai@ambershark
My situation is one thread create QOpenGLContext , and one thread create native OpenGLContext .
QOpenGLContext use QTs API as I posted , and OpenGLContext use opengl APIs like glGenTextue , glTexImage2d.I'm not sure use mutex can fix this situation or there is conflict between QtOpenGL and native OpenGL originally.
-
@ambershark
My situation is one thread create QOpenGLContext , and one thread create native OpenGLContext .
QOpenGLContext use QTs API as I posted , and OpenGLContext use opengl APIs like glGenTextue , glTexImage2d.I'm not sure use mutex can fix this situation or there is conflict between QtOpenGL and native OpenGL originally.
wrote on 18 Oct 2017, 09:31 last edited by@TL_Tsai I had assumed they were created in a single thread and shared.. hmm.
I'm not really sure how to help you. Threading issues are the most complicated to solve. It's difficult with knowledge of the project and source code. It's almost impossible without at least source code to look at.
I wish I had more advice but the information is just too limited. Good luck though, I'm sure you'll find it. :)
-
Why are you mixing both ?
1/10