瀏覽代碼

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 年之前
父節點
當前提交
d1a853bca7
共有 3 個檔案被更改,包括 11 行新增8 行删除
  1. 4
    5
      vncviewer/OSXPixelBuffer.cxx
  2. 3
    0
      vncviewer/Viewport.cxx
  3. 4
    3
      vncviewer/X11PixelBuffer.cxx

+ 4
- 5
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 @@ 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"));
}



+ 3
- 0
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 @@ 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);
}


+ 4
- 3
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 @@ 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;

Loading…
取消
儲存