summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorMike Morris <michael.patrick.morris@gmail.com>2014-10-08 14:47:41 -0400
committerMike Morris <michael.patrick.morris@gmail.com>2014-10-08 14:47:41 -0400
commit7aea160760a0ad8338d0b3e15419332c1794848c (patch)
treea5301337c0e067fe31da1118099c689d4977ede2 /common
parent36b7bb0c0991b3c5c3a7d001139b120bee854484 (diff)
downloadqtlocation-mapboxgl-7aea160760a0ad8338d0b3e15419332c1794848c.tar.gz
throw std::runtime_error instead of fprintf in HeadlessView, closes #481
Diffstat (limited to 'common')
-rw-r--r--common/headless_view.cpp36
1 files changed, 18 insertions, 18 deletions
diff --git a/common/headless_view.cpp b/common/headless_view.cpp
index d11f63dbd5..d19db57483 100644
--- a/common/headless_view.cpp
+++ b/common/headless_view.cpp
@@ -2,6 +2,8 @@
#include "headless_display.hpp"
#include <stdexcept>
+#include <sstream>
+#include <string>
namespace mbgl {
@@ -18,14 +20,12 @@ void HeadlessView::createContext() {
#if MBGL_USE_CGL
CGLError error = CGLCreateContext(display_->pixelFormat, NULL, &gl_context);
if (error) {
- fprintf(stderr, "Error creating GL context object\n");
- return;
+ throw std::runtime_error("Error creating GL context object\n");
}
error = CGLEnable(gl_context, kCGLCEMPEngine);
if (error != kCGLNoError ) {
- fprintf(stderr, "Error enabling OpenGL multithreading\n");
- return;
+ throw std::runtime_error("Error enabling OpenGL multithreading\n");
}
#endif
@@ -69,18 +69,18 @@ void HeadlessView::resize(uint16_t width, uint16_t height, float pixelRatio) {
GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
- fprintf(stderr, "Couldn't create framebuffer: ");
+ std::stringstream error("Couldn't create framebuffer: ");
switch (status) {
- case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT: fprintf(stderr, "incomplete attachment\n"); break;
- case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT: fprintf(stderr, "incomplete missing attachment\n"); break;
- case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT: fprintf(stderr, "incomplete dimensions\n"); break;
- case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT: fprintf(stderr, "incomplete formats\n"); break;
- case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT: fprintf(stderr, "incomplete draw buffer\n"); break;
- case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT: fprintf(stderr, "incomplete read buffer\n"); break;
- case GL_FRAMEBUFFER_UNSUPPORTED: fprintf(stderr, "unsupported\n"); break;
- default: fprintf(stderr, "other\n"); break;
+ case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT: (error << "incomplete attachment\n"); break;
+ case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT: error << "incomplete missing attachment\n"; break;
+ case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT: error << "incomplete dimensions\n"; break;
+ case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT: error << "incomplete formats\n"; break;
+ case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT: error << "incomplete draw buffer\n"; break;
+ case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT: error << "incomplete read buffer\n"; break;
+ case GL_FRAMEBUFFER_UNSUPPORTED: error << "unsupported\n"; break;
+ default: error << "other\n"; break;
}
- return;
+ throw std::runtime_error(error.str());
}
make_inactive();
@@ -151,13 +151,13 @@ void HeadlessView::make_active() {
#if MBGL_USE_CGL
CGLError error = CGLSetCurrentContext(gl_context);
if (error) {
- fprintf(stderr, "Switching OpenGL context failed\n");
+ throw std::runtime_error("Switching OpenGL context failed\n");
}
#endif
#if MBGL_USE_GLX
if (!glXMakeCurrent(x_display, glx_pixmap, gl_context)) {
- fprintf(stderr, "Switching OpenGL context failed\n");
+ throw std::runtime_error("Switching OpenGL context failed\n");
}
#endif
}
@@ -166,13 +166,13 @@ void HeadlessView::make_inactive() {
#if MBGL_USE_CGL
CGLError error = CGLSetCurrentContext(nullptr);
if (error) {
- fprintf(stderr, "Removing OpenGL context failed\n");
+ throw std::runtime_error("Removing OpenGL context failed\n");
}
#endif
#if MBGL_USE_GLX
if (!glXMakeCurrent(x_display, 0, NULL)) {
- fprintf(stderr, "Removing OpenGL context failed\n");
+ throw std::runtime_error("Removing OpenGL context failed\n");
}
#endif
}