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.
diff --git a/vncviewer/OSXPixelBuffer.cxx b/vncviewer/OSXPixelBuffer.cxx
index a3ee9d0..e9100f2 100644
--- a/vncviewer/OSXPixelBuffer.cxx
+++ b/vncviewer/OSXPixelBuffer.cxx
@@ -20,8 +20,6 @@
#include <config.h>
#endif
-#include <assert.h>
-
#include <ApplicationServices/ApplicationServices.h>
#include <FL/Fl_Window.H>
@@ -50,13 +48,14 @@
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 66a7841..4daff16 100644
--- a/vncviewer/Viewport.cxx
+++ b/vncviewer/Viewport.cxx
@@ -27,6 +27,7 @@
#include <rfb/CMsgWriter.h>
#include <rfb/LogWriter.h>
+#include <rfb/Exception.h>
// FLTK can pull in the X11 headers on some systems
#ifndef XK_VoidSymbol
@@ -452,6 +453,8 @@
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 d84357c..59b90e2 100644
--- a/vncviewer/X11PixelBuffer.cxx
+++ b/vncviewer/X11PixelBuffer.cxx
@@ -21,7 +21,6 @@
#include <config.h>
#endif
-#include <assert.h>
#include <stdlib.h>
#include <FL/x.H>
@@ -104,10 +103,12 @@
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;