From 08d580f68a02b7cd9eb4b8a93d9f32aa63db3a38 Mon Sep 17 00:00:00 2001 From: "Owen W. Taylor" Date: Mon, 8 Jun 2009 09:26:57 -0400 Subject: [PATCH] On bad blend strings, print the error if not returning it It's very common that there's no reasonable fallback to do if the blend or combine string you set isn't supported. So, rather than requiring everybody to pass in a GError purely to catch syntax erorrs, automatically g_warning() if a parse error is encountered and @error is NULL. http://bugzilla.openedhand.com/show_bug.cgi?id=1642 Signed-off-by: Robert Bragg --- clutter/cogl/cogl-material.h | 5 ++++- clutter/cogl/common/cogl-material.c | 30 +++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/clutter/cogl/cogl-material.h b/clutter/cogl/cogl-material.h index 66fbd8d5c..510ce8238 100644 --- a/clutter/cogl/cogl-material.h +++ b/clutter/cogl/cogl-material.h @@ -419,7 +419,8 @@ void cogl_material_set_alpha_test_function (CoglHandle material, * @error: A GError that may report lack of driver support if you give * separate blend string statements for the alpha channel and RGB * channels since some drivers or backends such as GLES 1.1 dont - * support this. + * support this. May be %NULL, in which case a warning will be + * printed out if an error is encountered. * * If not already familiar; please refer * here for an overview of what blend @@ -536,6 +537,8 @@ void cogl_material_remove_layer (CoglHandle material, * @blend_string: A Cogl blend string * describing the desired texture combine function. * @error: A GError that may report parse errors or lack of GPU/driver support. + * May be %NULL, in which case a warning will be printed out if an + * error is encountered. * * If not already familiar; you can refer * here for an overview of what blend diff --git a/clutter/cogl/common/cogl-material.c b/clutter/cogl/common/cogl-material.c index 68198858a..831fa30f1 100644 --- a/clutter/cogl/common/cogl-material.c +++ b/clutter/cogl/common/cogl-material.c @@ -533,6 +533,7 @@ cogl_material_set_blend (CoglHandle handle, CoglBlendStringStatement split[2]; CoglBlendStringStatement *rgb; CoglBlendStringStatement *a; + GError *internal_error = NULL; int count; g_return_val_if_fail (cogl_is_material (handle), FALSE); @@ -543,9 +544,19 @@ cogl_material_set_blend (CoglHandle handle, _cogl_blend_string_compile (blend_description, COGL_BLEND_STRING_CONTEXT_BLENDING, statements, - error); + &internal_error); if (!count) - return FALSE; + { + if (error) + g_propagate_error (error, internal_error); + else + { + g_warning ("Cannot compile blend description: %s\n", + internal_error->message); + g_error_free (internal_error); + } + return FALSE; + } if (statements[0].mask == COGL_BLEND_STRING_CHANNEL_MASK_RGBA) { @@ -806,6 +817,7 @@ cogl_material_set_layer_combine (CoglHandle handle, CoglBlendStringStatement split[2]; CoglBlendStringStatement *rgb; CoglBlendStringStatement *a; + GError *internal_error = NULL; int count; g_return_val_if_fail (cogl_is_material (handle), FALSE); @@ -817,9 +829,19 @@ cogl_material_set_layer_combine (CoglHandle handle, _cogl_blend_string_compile (combine_description, COGL_BLEND_STRING_CONTEXT_TEXTURE_COMBINE, statements, - error); + &internal_error); if (!count) - return FALSE; + { + if (error) + g_propagate_error (error, internal_error); + else + { + g_warning ("Cannot compile combine description: %s\n", + internal_error->message); + g_error_free (internal_error); + } + return FALSE; + } if (statements[0].mask == COGL_BLEND_STRING_CHANNEL_MASK_RGBA) {