changeset 79:5bcb329a5157

Fix bug of core dump caused by forget to check if parent is NULL, root.
author Thinker K.F. Li <thinker@branda.to>
date Wed, 20 Aug 2008 23:47:18 +0800
parents 3645e29e4986
children e548221c04eb
files examples/svg2code_ex/main.c src/redraw_man.c
diffstat 2 files changed, 11 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/examples/svg2code_ex/main.c	Wed Aug 20 23:33:04 2008 +0800
+++ b/examples/svg2code_ex/main.c	Wed Aug 20 23:47:18 2008 +0800
@@ -8,7 +8,7 @@
     svg2code_ex_t *svg2code;
     int r;
 
-    r = X_MB_init(":0.0", 200, 200, &rt);
+    r = X_MB_init(":0.0", 800, 600, &rt);
 
     svg2code = svg2code_ex_new(rt.rdman);
     X_MB_handle_connection(rt.display, rt.rdman, rt.tman);
--- a/src/redraw_man.c	Wed Aug 20 23:33:04 2008 +0800
+++ b/src/redraw_man.c	Wed Aug 20 23:47:18 2008 +0800
@@ -658,7 +658,7 @@
 #ifndef UNITTEST
 static void clean_canvas(cairo_t *cr) {
     /*! \todo clean to background color. */
-    cairo_set_source_rgb(cr, 0, 0, 0);
+    cairo_set_source_rgb(cr, 1, 1, 1);
     cairo_paint(cr);
 }
 
@@ -939,7 +939,7 @@
 static subject_t *ob_get_parent_subject(ob_factory_t *factory,
 					subject_t *cur_subject) {
     redraw_man_t *rdman;
-    coord_t *coord;
+    coord_t *coord, *parent_coord;
     geo_t *geo;
     subject_t *parent;
 
@@ -947,13 +947,17 @@
     switch(cur_subject->obj_type) {
     case OBJT_GEO:
 	geo = (geo_t *)cur_subject->obj;
-	coord = geo->shape->coord;
-	parent = coord->mouse_event;
+	parent_coord = geo->shape->coord;
+	parent = parent_coord->mouse_event;
 	break;
     case OBJT_COORD:
 	coord = (coord_t *)cur_subject->obj;
-	coord = coord->parent;
-	parent = coord->mouse_event;
+	parent_coord = coord->parent;
+	if(parent_coord == NULL) {
+	    parent = NULL;
+	    break;
+	}
+	parent = parent_coord->mouse_event;
 	break;
     default:
 	parent = NULL;