From 530cb40528a6fac2fe449bdb3932e443944edf57 Mon Sep 17 00:00:00 2001
From: Zach Pomerantz <zach@highfidelity.io>
Date: Wed, 30 Mar 2016 15:11:54 -0700
Subject: [PATCH] Check for valid qml gl context creation

---
 libraries/gl/src/gl/OffscreenGLCanvas.cpp   |  4 +++-
 libraries/gl/src/gl/OffscreenQmlSurface.cpp | 13 ++++---------
 2 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/libraries/gl/src/gl/OffscreenGLCanvas.cpp b/libraries/gl/src/gl/OffscreenGLCanvas.cpp
index 31bbc84cb2..8e5579f90b 100644
--- a/libraries/gl/src/gl/OffscreenGLCanvas.cpp
+++ b/libraries/gl/src/gl/OffscreenGLCanvas.cpp
@@ -38,11 +38,13 @@ bool OffscreenGLCanvas::create(QOpenGLContext* sharedContext) {
         _context->setShareContext(sharedContext);
     }
     _context->setFormat(getDefaultOpenGLSurfaceFormat());
+
     if (_context->create()) {
         _offscreenSurface->setFormat(_context->format());
         _offscreenSurface->create();
-        return true;
+        return _offscreenSurface->isValid();
     }
+    qWarning("Failed to create OffscreenGLCanvas context");
 
     return false;
 }
diff --git a/libraries/gl/src/gl/OffscreenQmlSurface.cpp b/libraries/gl/src/gl/OffscreenQmlSurface.cpp
index 1d9e6d0149..1d7824f789 100644
--- a/libraries/gl/src/gl/OffscreenQmlSurface.cpp
+++ b/libraries/gl/src/gl/OffscreenQmlSurface.cpp
@@ -134,14 +134,13 @@ QEvent* OffscreenQmlRenderThread::Queue::take() {
 }
 
 OffscreenQmlRenderThread::OffscreenQmlRenderThread(OffscreenQmlSurface* surface, QOpenGLContext* shareContext) : _surface(surface) {
-    qDebug() << "Building QML Renderer: creating context";
+    qDebug() << "Building QML Renderer";
     if (!_canvas.create(shareContext)) {
-        static const char* error = "Failed to create OffscreenGLCanvas";
-        qWarning() << error;
-        throw error;
+        qWarning("Failed to create OffscreenGLCanvas");
+        _quit = true;
+        return;
     };
 
-    qDebug() << "Building QML Renderer: creating render control";
     _renderControl = new QMyQuickRenderControl();
     QQuickWindow::setDefaultAlphaBuffer(true);
     // Create a QQuickWindow that is associated with our render control.
@@ -149,19 +148,15 @@ OffscreenQmlRenderThread::OffscreenQmlRenderThread(OffscreenQmlSurface* surface,
     // NOTE: Must be created on the main thread so that OffscreenQmlSurface can send it events
     // NOTE: Must be created on the rendering thread or it will refuse to render,
     //       so we wait until after its ctor to move object/context to this thread.
-    qDebug() << "Building QML Renderer: creating window";
     _quickWindow = new QQuickWindow(_renderControl);
     _quickWindow->setColor(QColor(255, 255, 255, 0));
     _quickWindow->setFlags(_quickWindow->flags() | static_cast<Qt::WindowFlags>(Qt::WA_TranslucentBackground));
 
     // We can prepare, but we must wait to start() the thread until after the ctor
-    qDebug() << "Building QML Renderer: moving to own thread";
     _renderControl->prepareThread(this);
     _canvas.getContextObject()->moveToThread(this);
     moveToThread(this);
 
-    qDebug() << "Building QML Renderer: complete";
-
     _queue.add(INIT);
 }