Browse Source

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.
tags/v1.3.90
Pierre Ossman 9 years ago
parent
commit
d1a853bca7
3 changed files with 11 additions and 8 deletions
  1. 4
    5
      vncviewer/OSXPixelBuffer.cxx
  2. 3
    0
      vncviewer/Viewport.cxx
  3. 4
    3
      vncviewer/X11PixelBuffer.cxx

+ 4
- 5
vncviewer/OSXPixelBuffer.cxx View File

#include <config.h> #include <config.h>
#endif #endif


#include <assert.h>

#include <ApplicationServices/ApplicationServices.h> #include <ApplicationServices/ApplicationServices.h>


#include <FL/Fl_Window.H> #include <FL/Fl_Window.H>
throw rfb::Exception(_("Not enough memory for framebuffer")); throw rfb::Exception(_("Not enough memory for framebuffer"));


lut = CGColorSpaceCreateDeviceRGB(); lut = CGColorSpaceCreateDeviceRGB();
assert(lut);
if (!lut)
throw rfb::Exception(_("Could not create framebuffer device"));


bitmap = CGBitmapContextCreate(data, width, height, 8, width*4, lut, bitmap = CGBitmapContextCreate(data, width, height, 8, width*4, lut,
kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Little); kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Little);
assert(bitmap);

CGColorSpaceRelease(lut); CGColorSpaceRelease(lut);
if (!bitmap)
throw rfb::Exception(_("Could not create framebuffer bitmap"));
} }





+ 3
- 0
vncviewer/Viewport.cxx View File



#include <rfb/CMsgWriter.h> #include <rfb/CMsgWriter.h>
#include <rfb/LogWriter.h> #include <rfb/LogWriter.h>
#include <rfb/Exception.h>


// FLTK can pull in the X11 headers on some systems // FLTK can pull in the X11 headers on some systems
#ifndef XK_VoidSymbol #ifndef XK_VoidSymbol
fb = new X11PixelBuffer(w, h); fb = new X11PixelBuffer(w, h);
#endif #endif
} catch (rdr::Exception& e) { } 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); fb = new FLTKPixelBuffer(w, h);
} }



+ 4
- 3
vncviewer/X11PixelBuffer.cxx View File

#include <config.h> #include <config.h>
#endif #endif


#include <assert.h>
#include <stdlib.h> #include <stdlib.h>


#include <FL/x.H> #include <FL/x.H>
if (!setupShm()) { if (!setupShm()) {
xim = XCreateImage(fl_display, fl_visual->visual, fl_visual->depth, xim = XCreateImage(fl_display, fl_visual->visual, fl_visual->depth,
ZPixmap, 0, 0, width, height, BitmapPad(fl_display), 0); 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); 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; data = (rdr::U8*)xim->data;

Loading…
Cancel
Save