diff --git a/libraries/gpu/src/gpu/GLBackendTextureTransfer.cpp b/libraries/gpu/src/gpu/GLBackendTextureTransfer.cpp index 90995c8e6f..f49eb3d7fa 100644 --- a/libraries/gpu/src/gpu/GLBackendTextureTransfer.cpp +++ b/libraries/gpu/src/gpu/GLBackendTextureTransfer.cpp @@ -22,7 +22,7 @@ using namespace gpu; GLTextureTransferHelper::GLTextureTransferHelper() { #ifdef THREADED_TEXTURE_TRANSFER - _canvas = std::make_shared(); + _canvas = QSharedPointer(new OffscreenGLCanvas(), &QObject::deleteLater); _canvas->create(QOpenGLContextWrapper::currentContext()); if (!_canvas->makeCurrent()) { qFatal("Unable to create texture transfer context"); @@ -30,6 +30,17 @@ GLTextureTransferHelper::GLTextureTransferHelper() { _canvas->doneCurrent(); initialize(true, QThread::LowPriority); _canvas->moveToThreadWithContext(_thread); + + // Clean shutdown on UNIX, otherwise _canvas is freed early + connect(qApp, &QCoreApplication::aboutToQuit, [&] { terminate(); }); +#endif +} + +GLTextureTransferHelper::~GLTextureTransferHelper() { +#ifdef THREADED_TEXTURE_TRANSFER + if (isStillRunning()) { + terminate(); + } #endif } @@ -52,8 +63,11 @@ void GLTextureTransferHelper::setup() { } void GLTextureTransferHelper::shutdown() { +#ifdef THREADED_TEXTURE_TRANSFER _canvas->doneCurrent(); _canvas->moveToThreadWithContext(qApp->thread()); + _canvas.reset(); +#endif } diff --git a/libraries/gpu/src/gpu/GLBackendTextureTransfer.h b/libraries/gpu/src/gpu/GLBackendTextureTransfer.h index 1e850586d4..1046fc9883 100644 --- a/libraries/gpu/src/gpu/GLBackendTextureTransfer.h +++ b/libraries/gpu/src/gpu/GLBackendTextureTransfer.h @@ -6,6 +6,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include #include #include "GLBackendShared.h" @@ -23,6 +24,7 @@ struct TextureTransferPackage { class GLTextureTransferHelper : public GenericQueueThread { public: GLTextureTransferHelper(); + ~GLTextureTransferHelper(); void transferTexture(const gpu::TexturePointer& texturePointer); void postTransfer(const gpu::TexturePointer& texturePointer); @@ -33,7 +35,7 @@ protected: void transferTextureSynchronous(const gpu::Texture& texture); private: - std::shared_ptr _canvas; + QSharedPointer _canvas; }; template