Merge pull request #8275 from jherico/web_entity_leak

Cleanup resources used by offscreen GL surfaces
This commit is contained in:
Brad Hefta-Gaub 2016-07-18 21:46:18 -07:00 committed by GitHub
commit 2e491e0afb
4 changed files with 20 additions and 9 deletions

View file

@ -36,7 +36,15 @@ OffscreenGLCanvas::~OffscreenGLCanvas() {
delete _logger; delete _logger;
_logger = nullptr; _logger = nullptr;
} }
_context->doneCurrent(); _context->doneCurrent();
delete _context;
_context = nullptr;
_offscreenSurface->destroy();
delete _offscreenSurface;
_offscreenSurface = nullptr;
} }
bool OffscreenGLCanvas::create(QOpenGLContext* sharedContext) { bool OffscreenGLCanvas::create(QOpenGLContext* sharedContext) {

View file

@ -34,8 +34,8 @@ public:
protected: protected:
std::once_flag _reportOnce; std::once_flag _reportOnce;
QOpenGLContext* _context; QOpenGLContext* _context{ nullptr };
QOffscreenSurface* _offscreenSurface; QOffscreenSurface* _offscreenSurface{ nullptr };
QOpenGLDebugLogger* _logger{ nullptr }; QOpenGLDebugLogger* _logger{ nullptr };
}; };

View file

@ -28,16 +28,17 @@ QOpenGLContext* QOpenGLContextWrapper::currentContext() {
return QOpenGLContext::currentContext(); return QOpenGLContext::currentContext();
} }
QOpenGLContextWrapper::QOpenGLContextWrapper() : QOpenGLContextWrapper::QOpenGLContextWrapper() :
_context(new QOpenGLContext) _ownContext(true), _context(new QOpenGLContext) { }
{
}
QOpenGLContextWrapper::QOpenGLContextWrapper(QOpenGLContext* context) : QOpenGLContextWrapper::QOpenGLContextWrapper(QOpenGLContext* context) :
_context(context) _context(context) { }
{
QOpenGLContextWrapper::~QOpenGLContextWrapper() {
if (_ownContext) {
delete _context;
_context = nullptr;
}
} }
void QOpenGLContextWrapper::setFormat(const QSurfaceFormat& format) { void QOpenGLContextWrapper::setFormat(const QSurfaceFormat& format) {

View file

@ -23,6 +23,7 @@ class QOpenGLContextWrapper {
public: public:
QOpenGLContextWrapper(); QOpenGLContextWrapper();
QOpenGLContextWrapper(QOpenGLContext* context); QOpenGLContextWrapper(QOpenGLContext* context);
virtual ~QOpenGLContextWrapper();
void setFormat(const QSurfaceFormat& format); void setFormat(const QSurfaceFormat& format);
bool create(); bool create();
void swapBuffers(QSurface* surface); void swapBuffers(QSurface* surface);
@ -40,6 +41,7 @@ public:
private: private:
bool _ownContext { false };
QOpenGLContext* _context { nullptr }; QOpenGLContext* _context { nullptr };
}; };