Hi, The following code segfaults. GDB suggest it is because "buf" is a null pointer. A debug statement as the last line of AGWindow constructor will show that buf is not null. Another debug statement right after the AGWindow constructor call in main() will show that window->buf is null. This does not make any sense to me. Is this a bug ? Any suggestions ?
Incidentally this example http://www.fltk.org/applications/articles.php?L898 from which the code below was modified does not compile. After fixing the compiler errors it does produce a similar segfault. -------------------------------------------------------------------------- #File aggwin.h #include <math.h> #include <FL/Fl.H> #include <FL/Fl_Double_Window.H> #include <FL/fl_draw.H> #include "agg.h" #ifndef AGG_LITE_WINDOW_DEF #define AGG_LITE_WINDOW_DEF class AGWindow : public Fl_Double_Window { public: AGWindow(int x, int y, int w, int h, char *s); ~AGWindow() { delete [] buf; delete rbuf; delete ras; delete ren; }; unsigned char *buf; private: agg::rendering_buffer *rbuf; agg::rasterizer *ras; agg::renderer<agg::span_rgb24> *ren; void draw(void); void move_to(double x, double y); void line_to(double x, double y); void draw_line(double x1, double y1, double x2, double y2, double width); void render(unsigned char r,unsigned char g,unsigned char b,unsigned char a); }; #endif ----------------------------------------------------------------------- #file aggwin.cpp #include "aggwin.h" AGWindow::AGWindow(int x, int y, int w, int h, char *s) : Fl_Double_Window(x,y,w,h,s) { // Allocate the framebuffer unsigned char* buf = new unsigned char[w * h * 3]; // Create the rendering buffer rbuf = new agg::rendering_buffer(buf, w, h, w * 3); // Create the renderer and the rasterizer ren = new agg::renderer<agg::span_rgb24>(*rbuf); ras = new agg::rasterizer; ras->gamma(1.3); ras->filling_rule(agg::fill_non_zero); } void AGWindow::move_to(double x, double y) { ras->move_to_d(x, y); } void AGWindow::line_to(double x, double y) { ras->line_to_d(x, y); } void AGWindow::draw_line(double x1, double y1, double x2, double y2, double width) { double dx = x2 - x1; double dy = y2 - y1; double d = sqrt(dx*dx + dy*dy); dx = width * (y2 - y1) / d; dy = width * (x2 - x1) / d; ras->move_to_d(x1 - dx, y1 + dy); ras->line_to_d(x2 - dx, y2 + dy); ras->line_to_d(x2 + dx, y2 - dy); ras->line_to_d(x1 + dx, y1 - dy); } void AGWindow::render(unsigned char r, unsigned char g, unsigned char b, unsigned char a ) { ras->render(*ren, agg::rgba8(r, g, b, a)); } ----------------------------------------------------------------------- #file main.cpp#include <FL/Fl.H> #include "aggwin.h" using namespace std; void AGWindow::draw(void) { draw_line(0, 0, 50, 50, 1.0); render(0, 0, 0, 120); fl_draw_image(buf,0,0,w(),h()); } int main(int argc, char ** argv) { AGWindow *window; Fl::visual(FL_RGB); window = new AGWindow(0, 0, 600, 400, "Test program"); window->end(); window->show(argc, argv); return(Fl::run()); } ======================================================================== GDB Backtrace Program received signal SIGSEGV, Segmentation fault. 0x0000000000000000 in ?? () (gdb) bt #0 0x0000000000000000 in ?? () #1 0x00007ffff7baf9c0 in ?? () from /usr/lib/libfltk.so.1.1 #2 0x00007ffff7bb0203 in fl_draw_image(unsigned char const*, int, int, int, int, int, int) () from /usr/lib/libfltk.so.1.1 #3 0x0000000000403e09 in AGWindow::draw (this=0x612b60) at test.cpp:10 #4 0x00007ffff7b6dd6b in Fl_Double_Window::flush(int) () from /usr/lib/libfltk.so.1.1 #5 0x00007ffff7b60c33 in Fl::flush() () from /usr/lib/libfltk.so.1.1 #6 0x00007ffff7b60e7d in Fl::wait(double) () from /usr/lib/libfltk.so.1.1 #7 0x00007ffff7b60fcd in Fl::run() () from /usr/lib/libfltk.so.1.1 #8 0x0000000000403ea9 in main (argc=1, argv=0x7fffffffe138) at test.cpp:20 regards bthomas _______________________________________________ fltk mailing list [email protected] http://lists.easysw.com/mailman/listinfo/fltk

