changeset 511:caa087976b17 Android_Skia

Fix the issue of segmentation fault when the pattern of a mbe is not setted. For Skia graphic engine, a mbe does not always have a pattern. For example, a color paint does not set a pattern on a mbe for a shape. So, we check if pattern is setted before accessing it.
author Thinker K.F. Li <thinker@branda.to>
date Tue, 01 Dec 2009 22:55:27 +0800
parents 371d88fc655f
children d186d1e24458
files src/graph_engine_skia.cpp
diffstat 1 files changed, 15 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/graph_engine_skia.cpp	Tue Dec 01 22:55:27 2009 +0800
+++ b/src/graph_engine_skia.cpp	Tue Dec 01 22:55:27 2009 +0800
@@ -192,25 +192,28 @@
 _prepare_paint(mbe_t *mbe, SkPaint::Style style) {
     SkPaint *paint = mbe->paint;
     mbe_pattern_t *ptn = mbe->states->ptn;
-    SkShader *shader = ptn->shader;
+    SkShader *shader;
     co_aix matrix[6];
     SkMatrix skmatrix;
 
     paint->setStyle(style);
     
-    /* Local matrix of SkShader is a mapping from source pattern to
-     * user space.  Unlikely, for Cairo is a mapping from user space
-     * to source pattern.
-     */
-    matrix_mul(mbe->states->matrix, ptn->matrix, matrix);
-    MB_MATRIX_2_SKMATRIX(skmatrix, matrix);
-    shader->setLocalMatrix(skmatrix);
-    paint->setShader(shader);
+    if(ptn != NULL) {
+	/* Local matrix of SkShader is a mapping from source pattern to
+	 * user space.  Unlikely, for Cairo is a mapping from user space
+	 * to source pattern.
+	 */
+	shader = ptn->shader;
+	matrix_mul(mbe->states->matrix, ptn->matrix, matrix);
+	MB_MATRIX_2_SKMATRIX(skmatrix, matrix);
+	shader->setLocalMatrix(skmatrix);
+	paint->setShader(shader);
+    }
 
     if(style == SkPaint::kStroke_Style)
 	paint->setStrokeWidth(CO_AIX_2_SKSCALAR(mbe->states->line_width));
 
-    if(ptn->has_size)
+    if(ptn != NULL && ptn->has_size)
 	_prepare_sized_pattern(mbe, ptn);
 }
 
@@ -219,7 +222,7 @@
     mbe_pattern_t *ptn = mbe->states->ptn;
     
     mbe->paint->reset();
-    if(ptn->has_size)
+    if(ptn != NULL && ptn->has_size)
 	_finish_sized_pattern(mbe);
 }
 
@@ -512,6 +515,7 @@
 			   MB_CO_COMP_2_SK(r),
 			   MB_CO_COMP_2_SK(g),
 			   MB_CO_COMP_2_SK(b));
+    canvas->paint->ptn = NULL;
 }
 
 void mbe_set_scaled_font(mbe_t *canvas,