Merge pull request #7637 from zzmp/fix/tex-transfer-free

Cleanly shutdown the texture transfer thread on quit
This commit is contained in:
Brad Hefta-Gaub 2016-04-12 19:28:51 -07:00
commit 0f8842f582
2 changed files with 18 additions and 2 deletions

View file

@ -22,7 +22,7 @@ using namespace gpu;
GLTextureTransferHelper::GLTextureTransferHelper() {
#ifdef THREADED_TEXTURE_TRANSFER
_canvas = std::make_shared<OffscreenGLCanvas>();
_canvas = QSharedPointer<OffscreenGLCanvas>(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
}

View file

@ -6,6 +6,7 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <QSharedPointer>
#include <GenericQueueThread.h>
#include "GLBackendShared.h"
@ -23,6 +24,7 @@ struct TextureTransferPackage {
class GLTextureTransferHelper : public GenericQueueThread<TextureTransferPackage> {
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<OffscreenGLCanvas> _canvas;
QSharedPointer<OffscreenGLCanvas> _canvas;
};
template <typename F>