gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
path: root/agg-plot/bitmap-plot.cpp
diff options
context:
space:
mode:
authorFrancesco Abbate <francesco.bbt@gmail.com>2011年12月18日 00:02:19 +0100
committerFrancesco Abbate <francesco.bbt@gmail.com>2011年12月18日 00:02:19 +0100
commitee563973094a8235631d5208bd672f8cbbe15fdc (patch)
tree6a72a6e6ece3cb9a96fc221f3e04922e63f42f00 /agg-plot/bitmap-plot.cpp
parentef0f158b491b4211c392ce4c4c50891b6d5631de (diff)
downloadgsl-shell-ee563973094a8235631d5208bd672f8cbbe15fdc.tar.gz
Eliminate C++ exceptions from graphical system implementation
The rationale is that everything is simpler without C++ exceptions. No exceptions are raised in the C++ code and errors are handler in the tradition C fashion. lua_error is not directly called from C++ functions that may allocate a non POD object on the stack. If the C++ "new" operator raise an exception the program will abort. The idea is that handle such an improbable occurrence greatly complicates the code. Where big chunks of memory are allocated the nothrow variant of "new" is used, the returned pointer is verified and an error is raised if the allocation failed. In the Windows code the bitmap allocation for image may raise an unhandled exception in there is not enough memory. The memory allocation is done inside the AGG library so it difficult to change its behavior.
Diffstat (limited to 'agg-plot/bitmap-plot.cpp')
-rw-r--r--agg-plot/bitmap-plot.cpp 43
1 files changed, 23 insertions, 20 deletions
diff --git a/agg-plot/bitmap-plot.cpp b/agg-plot/bitmap-plot.cpp
index ec92f131..5807c74e 100644
--- a/agg-plot/bitmap-plot.cpp
+++ b/agg-plot/bitmap-plot.cpp
@@ -15,32 +15,35 @@ extern "C" {
void
bitmap_save_image_cpp (sg_plot *p, const char *fn, unsigned w, unsigned h,
- gslshell::ret_status& st)
+ gslshell::ret_status& st)
{
- try {
- agg::rendering_buffer rbuf_tmp;
- unsigned row_size = w * (gslshell::bpp / 8);
- unsigned buf_size = h * row_size;
- agg::pod_array<unsigned char> buffer(buf_size);
- rbuf_tmp.attach(buffer.data(), w, h, gslshell::flip_y ? row_size : -row_size);
+ agg::rendering_buffer rbuf_tmp;
+ unsigned row_size = w * (gslshell::bpp / 8);
+ unsigned buf_size = h * row_size;
- canvas can(rbuf_tmp, w, h, colors::white);
- agg::trans_affine mtx(w, 0.0, 0.0, h, 0.0, 0.0);
+ unsigned char* buffer = new(std::nothrow) unsigned char[buf_size];
+ if (!buffer)
+ {
+ st.error("cannot allocate memory", "plot save");
+ return;
+ }
+
+ rbuf_tmp.attach(buffer, w, h, gslshell::flip_y ? row_size : -row_size);
+
+ canvas can(rbuf_tmp, w, h, colors::white);
+ agg::trans_affine mtx(w, 0.0, 0.0, h, 0.0, 0.0);
- agg::rect_base<int> r = rect_of_slot_matrix<int>(mtx);
- can.clear_box(r);
+ agg::rect_base<int> r = rect_of_slot_matrix<int>(mtx);
+ can.clear_box(r);
- p->draw(can, mtx);
+ p->draw(can, mtx);
- bool success = platform_support_ext::save_image_file (rbuf_tmp, fn);
+ bool success = platform_support_ext::save_image_file (rbuf_tmp, fn);
- if (! success)
- st.error("cannot save image file", "plot save");
- }
- catch (std::exception& e)
- {
- st.error(e.what(), "plot save");
- }
+ if (! success)
+ st.error("cannot save image file", "plot save");
+
+ delete [] buffer;
}
int
generated by cgit v1.2.3 (git 2.25.1) at 2025年09月12日 14:23:54 +0000

AltStyle によって変換されたページ (->オリジナル) /