From d1a853bca7a70467915b3759aa9de5e63a5e8edb Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Fri, 10 Oct 2014 13:37:35 +0200 Subject: [PATCH] Use exceptions rather than asserts for for "normal" errors Although these are rare, they are still not indicative of bugs so an exception (which ends up in the log and might also be shown to the user) is more appropriate than an assert. Asserts should only be used to catch blatant API misuse and similar. --- vncviewer/OSXPixelBuffer.cxx | 9 ++++----- vncviewer/Viewport.cxx | 3 +++ vncviewer/X11PixelBuffer.cxx | 7 ++++--- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/vncviewer/OSXPixelBuffer.cxx b/vncviewer/OSXPixelBuffer.cxx index a3ee9d0d..e9100f27 100644 --- a/vncviewer/OSXPixelBuffer.cxx +++ b/vncviewer/OSXPixelBuffer.cxx @@ -20,8 +20,6 @@ #include #endif -#include - #include #include @@ -50,13 +48,14 @@ OSXPixelBuffer::OSXPixelBuffer(int width, int height) : throw rfb::Exception(_("Not enough memory for framebuffer")); lut = CGColorSpaceCreateDeviceRGB(); - assert(lut); + if (!lut) + throw rfb::Exception(_("Could not create framebuffer device")); bitmap = CGBitmapContextCreate(data, width, height, 8, width*4, lut, kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Little); - assert(bitmap); - CGColorSpaceRelease(lut); + if (!bitmap) + throw rfb::Exception(_("Could not create framebuffer bitmap")); } diff --git a/vncviewer/Viewport.cxx b/vncviewer/Viewport.cxx index 66a78412..4daff164 100644 --- a/vncviewer/Viewport.cxx +++ b/vncviewer/Viewport.cxx @@ -27,6 +27,7 @@ #include #include +#include // FLTK can pull in the X11 headers on some systems #ifndef XK_VoidSymbol @@ -452,6 +453,8 @@ PlatformPixelBuffer* Viewport::createFramebuffer(int w, int h) fb = new X11PixelBuffer(w, h); #endif } catch (rdr::Exception& e) { + vlog.error(_("Unable to create platform specific framebuffer: %s"), e.str()); + vlog.error(_("Using platform independent framebuffer")); fb = new FLTKPixelBuffer(w, h); } diff --git a/vncviewer/X11PixelBuffer.cxx b/vncviewer/X11PixelBuffer.cxx index d84357c4..59b90e2c 100644 --- a/vncviewer/X11PixelBuffer.cxx +++ b/vncviewer/X11PixelBuffer.cxx @@ -21,7 +21,6 @@ #include #endif -#include #include #include @@ -104,10 +103,12 @@ X11PixelBuffer::X11PixelBuffer(int width, int height) : if (!setupShm()) { xim = XCreateImage(fl_display, fl_visual->visual, fl_visual->depth, ZPixmap, 0, 0, width, height, BitmapPad(fl_display), 0); - assert(xim); + if (!xim) + throw rfb::Exception(_("Could not create framebuffer image")); xim->data = (char*)malloc(xim->bytes_per_line * xim->height); - assert(xim->data); + if (!xim->data) + throw rfb::Exception(_("Not enough memory for framebuffer")); } data = (rdr::U8*)xim->data; -- 2.39.5