cogl-material-arbfp: Use separate buffers when calling g_ascii_dtostr

g_ascii_dtostr was being used in four separate arguments to
g_string_append_printf but all invocations of it were using the same
buffer. This would end up with all of the arguments having the same
value which would depend on whichever order the compiler evaluates
them in. This patches changes it to use a multi-dimensional array and
a loop to fill in the separate buffers.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2219
This commit is contained in:
Neil Roberts 2010-07-17 12:40:19 +01:00 committed by Emmanuele Bassi
parent 90b74458d2
commit 76d8119a7f

View File

@ -525,24 +525,25 @@ setup_arg (CoglMaterial *material,
CoglMaterialLayer *authority = CoglMaterialLayer *authority =
_cogl_material_layer_get_authority (layer, state); _cogl_material_layer_get_authority (layer, state);
CoglMaterialLayerBigState *big_state = authority->big_state; CoglMaterialLayerBigState *big_state = authority->big_state;
char buf[G_ASCII_DTOSTR_BUF_SIZE]; char buf[4][G_ASCII_DTOSTR_BUF_SIZE];
int i;
arg->type = COGL_MATERIAL_BACKEND_ARBFP_ARG_TYPE_CONSTANT; arg->type = COGL_MATERIAL_BACKEND_ARBFP_ARG_TYPE_CONSTANT;
arg->name = "constant%d"; arg->name = "constant%d";
arg->constant_id = priv->next_constant_id++; arg->constant_id = priv->next_constant_id++;
for (i = 0; i < 4; i++)
g_ascii_dtostr (buf[i], G_ASCII_DTOSTR_BUF_SIZE,
big_state->texture_combine_constant[i]);
g_string_append_printf (priv->source, g_string_append_printf (priv->source,
"PARAM constant%d = " "PARAM constant%d = "
" {%s, %s, %s, %s};\n", " {%s, %s, %s, %s};\n",
arg->constant_id, arg->constant_id,
g_ascii_dtostr (buf, sizeof (buf), buf[0],
big_state->texture_combine_constant[0]), buf[1],
g_ascii_dtostr (buf, sizeof (buf), buf[2],
big_state->texture_combine_constant[1]), buf[3]);
g_ascii_dtostr (buf, sizeof (buf),
big_state->texture_combine_constant[2]),
g_ascii_dtostr (buf, sizeof (buf),
big_state->texture_combine_constant[3]));
break; break;
} }
case GL_PRIMARY_COLOR: case GL_PRIMARY_COLOR: