lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I attached the C program.

These runs are making me very suspicious of font config. But.. I have
tried three different versions and also tried different fonts and the
fault stays.

When I stop at the segfault in the debugger memory has been corrupted
with the name of the font which has been written on top of some
pointers. Trying to use ASCII letters for a pointer makes a seg fault.
I haven't been able to catch who is corrupting the memory.

root@OpenWrt:/# cairo
jds-1
jds-2
jds-3
jds-4
jds-5
jds-6
jds-7
jds-8
jds-9
jds-10
jds-11
jds-12
jds-13
jds-14
root@OpenWrt:/# cairo
jds-1
jds-2
jds-3
jds-4
jds-5
jds-6
jds-7
jds-8
Segmentation fault
root@OpenWrt:/# rm -rf /usr/share/fontconfig/cache
root@OpenWrt:/# cairo
jds-1
jds-2
jds-3
jds-4
jds-5
jds-6
jds-7
jds-8
jds-9
jds-10
jds-11
jds-12
jds-13
jds-14
root@OpenWrt:/#



-- 
Jon Smirl
jonsmirl@gmail.com
/*************************************************************************
 * Cairo Frame Buffer demo
 * (c) 2004 Amaury Jacquot <sxpert@esitcom.org>
 * This program is licensed under the GNU GPL version 2 or later license
 ************************************************************************/

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <string.h>
#include <sys/mman.h>
#include <cairo/cairo.h>
#include <sys/ioctl.h>

#if 0
int main(int argc, char **argv) {
	long int screensize = 0;
	int stride;
	unsigned char* fbp = 0;
	cairo_t* cr;
	cairo_surface_t *surface;


	stride = cairo_format_stride_for_width (CAIRO_FORMAT_ARGB32, 240);
printf("Stride is %d\n", stride);
	// calculates size
	screensize = stride * 320;

	// map the device to memory 
	fbp = (char *) malloc(screensize);

	surface = cairo_image_surface_create_for_data (fbp, CAIRO_FORMAT_ARGB32, 
		240, 320, stride); 
	cr = cairo_create (surface);
	cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
	cairo_rectangle(cr, 0, 0, 240, 320);
	cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
	cairo_move_to (cr, 5, 30);
	cairo_set_font_size (cr, 24.0);
	cairo_show_text (cr, "Space is magic");
	cairo_set_source_rgb (cr, 1.0, 0, 1.0);
	cairo_move_to (cr, 50, 50);
	cairo_line_to (cr, 200, 200);
	cairo_set_line_width(cr, 2);
	cairo_stroke (cr);

	fb_display(fbp, NULL, 240, 320, 0, 0, 0, 0);

	
	return 0;
}


int main(){
	int fbfd = 0;
	struct fb_var_screeninfo vinfo;
	struct fb_fix_screeninfo finfo;
	long int screensize = 0;
	int ret;
	char* fbp = 0;
	cairo_t* cr;
	cairo_surface_t *surface;

	// open the frame buffer file for reading & writing
	fbfd = open ( "/dev/fb0", O_RDWR );
	if (!fbfd) {
		printf ("Error: can't open framebuffer device.\n");
		exit (1);
	}
	printf ("The framebuffer device was opened successfully\n");

	if (ioctl (fbfd, FBIOGET_FSCREENINFO, &finfo)) {
		printf ("Error reading fixed information\n");
		close (fbfd);
		exit (2);
	}

	if (ioctl (fbfd, FBIOGET_VSCREENINFO, &vinfo)) {
		printf ("Error reading variable information\n");
		close (fbfd);
		exit (3);
	}

	// print info about the buffer
	printf ("%dx%d, %dbpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel);

	// calculates size
	screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;

	// map the device to memory 
	fbp = (char*) mmap (0, screensize, PROT_READ PROT_WRITE, MAP_SHARED, fbfd, 0);

	memset(fbp, 0x0, screensize);

	if ((int)fbp == -1) {
		printf ("Error: failed to map framebuffer device to memory\n");
		close (fbfd);
		exit (4);
	}

	printf ("The framebuffer device was successfully mapped to memory\n");

	surface = cairo_image_surface_create_for_data (fbp, CAIRO_FORMAT_RGB16_565, 
		vinfo.xres, vinfo.yres, cairo_format_stride_for_width (CAIRO_FORMAT_RGB16_565, vinfo.xres)); 
	cr = cairo_create (surface);
printf("surface %x cr %x\n", surface, cr);
	cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
	cairo_rectangle(cr, 0, 0, 240, 320);
	cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
	cairo_move_to (cr, 5, 30);
	cairo_set_font_size (cr, 24.0);
	cairo_show_text (cr, "Space is magic");
	cairo_set_source_rgb (cr, 1.0, 0, 1.0);
	cairo_move_to (cr, 50, 50);
	cairo_line_to (cr, 200, 200);
	cairo_set_line_width(cr, 2);
	cairo_stroke (cr);

	memset(fbp, 0xFF, screensize/8);

	
	munmap (fbp, screensize);
	close (fbfd);
	return 0;
}

#endif

#include <stdio.h> 
#include <stdlib.h> 
#include <unistd.h> 
#include <fcntl.h> 
#include <linux/fb.h> 
#include <sys/mman.h> 
#include <sys/ioctl.h> 

typedef struct _cairo_linuxfb_device { 
        int fb_fd; 
        char *fb_data; 
        long fb_screensize; 
        struct fb_var_screeninfo fb_vinfo; 
        struct fb_fix_screeninfo fb_finfo; 
} cairo_linuxfb_device_t; 

static 
void cairo_linuxfb_surface_destroy(void *device) 
{ 
        cairo_linuxfb_device_t *dev = (cairo_linuxfb_device_t *)device; 

        if (dev == NULL) { 
                return; 
        } 
        munmap(dev->fb_data, dev->fb_screensize); 
        close(dev->fb_fd); 
        free(dev); 
} 

cairo_surface_t *cairo_linuxfb_surface_create(const char *fb_name) 
{ 
        cairo_linuxfb_device_t *device; 
        cairo_surface_t *surface; 

        if (fb_name == NULL) { 
                fb_name = "/dev/fb0"; 
        } 

        device = malloc(sizeof(*device)); 

        // Open the file for reading and writing 
        device->fb_fd = open(fb_name, O_RDWR); 
        if (device->fb_fd == -1) { 
                perror("Error: cannot open framebuffer device"); 
                exit(1); 
        } 

        // Get variable screen information 
        if (ioctl(device->fb_fd, FBIOGET_VSCREENINFO, &device->fb_vinfo) == -1) { 
                perror("Error reading variable information"); 
                exit(3); 
        } 

        // Figure out the size of the screen in bytes 
        device->fb_screensize = device->fb_vinfo.xres * device->fb_vinfo.yres 
                                * device->fb_vinfo.bits_per_pixel / 8; 

        // Map the device to memory 
        device->fb_data = (char *)mmap(0, device->fb_screensize, 
                                       PROT_READ | PROT_WRITE, MAP_SHARED, 
                                       device->fb_fd, 0); 
        if ((int)device->fb_data == -1) { 
                perror("Error: failed to map framebuffer device to memory"); 
                exit(4); 
        } 

        // Get fixed screen information 
        if (ioctl(device->fb_fd, FBIOGET_FSCREENINFO, &device->fb_finfo) == -1) { 
                perror("Error reading fixed information"); 
                exit(2); 
        } 

        surface = cairo_image_surface_create_for_data(device->fb_data, 
                      CAIRO_FORMAT_RGB16_565, 
                      device->fb_vinfo.xres, 
                      device->fb_vinfo.yres, 
                      cairo_format_stride_for_width(CAIRO_FORMAT_RGB16_565, 
device->fb_vinfo.xres)); 
        cairo_surface_set_user_data(surface, NULL, device, 
&cairo_linuxfb_surface_destroy); 

        return surface; 
} 

int main (int argc, char *argv[]) 
{ 
        cairo_surface_t *surface; 
        cairo_t *cr; 

        surface = cairo_linuxfb_surface_create(NULL); 
printf("jds-1\n");
        cr = cairo_create(surface); 
printf("jds-2\n");

        cairo_set_source_rgb(cr, 1, 1, 1); 
printf("jds-3\n");
	cairo_paint(cr);
printf("jds-4\n");

        cairo_select_font_face(cr, "Sans", CAIRO_FONT_SLANT_NORMAL, 
CAIRO_FONT_WEIGHT_BOLD); 
printf("jds-5\n");
        cairo_set_font_size(cr, 320/6); 
printf("jds-6\n");
        cairo_set_source_rgb(cr, 0, 0, 0); 
printf("jds-7\n");
        cairo_move_to(cr, 0, 240/4); 
printf("jds-8\n");
        cairo_show_text(cr, "Hello cairo!"); 
printf("jds-9\n");

        cairo_select_font_face(cr, "Sans", CAIRO_FONT_SLANT_NORMAL, 
CAIRO_FONT_WEIGHT_NORMAL); 
printf("jds-10\n");
        cairo_set_font_size(cr, 320/8); 
printf("jds-11\n");
        cairo_set_source_rgb(cr, 0.0, 0.0, 1.0); 
printf("jds-12\n");
        cairo_move_to(cr, 0, 3*240/4); 
printf("jds-13\n");
        cairo_text_path(cr, "Lua calling..."); 
printf("jds-14\n");

        cairo_destroy(cr); 
        cairo_surface_destroy(surface); 

        return 0; 
}