Skip to content

Commit ffa5b37

Browse files
committed
Perform QOffscreenSurface creation and deletion on the main (gui) thread to avoid warnings on Windows
1 parent 9194156 commit ffa5b37

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

libvis/src/libvis/opengl_context_qt.cc

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,18 @@
3434

3535
#include "libvis/glew.h"
3636
#include "libvis/logging.h"
37+
#include "libvis/qt_thread.h"
3738

3839
namespace vis {
3940

4041
OpenGLContextQt::~OpenGLContextQt() {
4142
// Delete the surface (since we always own it), but not the context (we might
4243
// own it, but then it should be deleted by Deinitialize()).
43-
delete surface;
44+
if (surface) {
45+
RunInQtThreadBlocking([&](){
46+
delete surface;
47+
});
48+
}
4449
}
4550

4651
bool OpenGLContextQt::InitializeWindowless(OpenGLContextImpl* sharing_context) {
@@ -71,17 +76,21 @@ bool OpenGLContextQt::InitializeWindowless(OpenGLContextImpl* sharing_context) {
7176

7277
surface = new QOffscreenSurface();
7378
surface->setFormat(context->format());
74-
// NOTE: On some platforms, create() must be called on the main (GUI) thread.
75-
// This is not enforced here at all.
76-
surface->create();
79+
RunInQtThreadBlocking([&](){
80+
surface->create();
81+
});
7782

7883
return true;
7984
}
8085

8186
void OpenGLContextQt::Deinitialize() {
8287
delete context;
8388
context = nullptr;
84-
delete surface;
89+
if (surface) {
90+
RunInQtThreadBlocking([&](){
91+
delete surface;
92+
});
93+
}
8594
surface = nullptr;
8695
}
8796

@@ -94,9 +103,9 @@ void OpenGLContextQt::AttachToCurrent() {
94103

95104
surface = new QOffscreenSurface();
96105
surface->setFormat(context->format());
97-
// NOTE: On some platforms, create() must be called on the main (GUI) thread.
98-
// This is not enforced here at all.
99-
surface->create();
106+
RunInQtThreadBlocking([&](){
107+
surface->create();
108+
});
100109
}
101110
}
102111

0 commit comments

Comments
 (0)